Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Can't pip install subprocess
-
I am attempting to install my first module with Pythonista and running into an error that I'm guessing is the result of my improper use of pip.
I'm attempting this from inside the console for 3.6.
I've tried:
-
python -m pip install subprocess
(invalid syntax on pip) -
python pip install subprocess
(invalid syntax on pip) -
pip install subprocess
(invalid syntax on install)
I've read over the information at http://omz-software.com/pythonista/docs/installing/index.html , but I still must be missing something.
Thanks!
-
-
Python comes with
subprocess
builtin. You do not need to install it. Justimport subprocess
In your Python code and you are off to the races. -
Of course, subprocess in pythonista doesn't actually do anything (just a bunch of stubs), since iOS doesn't allow spawning processes!
Bottom line, pythonista can only install pure python modules (or modules that use cffi with libraries that ship with iOS), and cannot use subprocesses.
-
Also... Note that while pythonista includes docs from the standard library, there is much in the standard library python docs that doesn't apply. For instance, obviously there is not virtualenv.
-
Take a look at https://github.com/ywangd/stash (or maybe bennr's fork), which includes a bash-like shell for pythonista. There is a pip command, which mostly works for pure py modules.
-
Like @ccc and @JonB already explained,
subprocess
can not really be used with pythonista. There is however a workaround. StaSh (a bash-like shell) provides a command calledmonkeylord
, which can be used to emulate subprocess behaviour, albeit still limited and maybe only working with python 2.If you are interested in trying this fake
subprocess
module, install StaSh, then in StaSh runmonkeylord enable subprocess
, then runpython <path to your file here>
. In this case,subprocess
will use StaSh as a shell instead of the system shell. Due to this, the exact behavior may differ from a PC. Also, the last work on this was done in 2016, so it may be outdated.(invalid syntax on pip)
Just so you know: The shell in pythonista (when you swipe from right to left in the editor) is a python shell, not a bash shell. It can be used to execute python code (e.g.
print(2**10 % 3)
), but not shell commands likepip
orecho
. Use StaSh for such cases instead.@JonB said:
(or maybe bennr's fork)
Thanks for the mention, but most of the code in my fork is/will be merged back into the main repo (I got maintainer access)..
-
That is a bit disheartening.... I have used the following on windows with Python 3.6 and was hoping to convert it to Phthonista so I could run it from an iPhone or iPad. But it sounds like I need to look for a different solution.
import os import sys import subprocess from socket import * subprocess.call("cls", shell=True) theargis = '' if len(sys.argv) > 1: theargis +=str(sys.argv[1]) if theargis > '': host = theargis print ("Using Server Address of " + theargis + ":") else: host = "53.68.241.25" print ("Using Default Address of " + host + ":") port = 13000 addr = (host, port) UDPSock = socket(AF_INET, SOCK_DGRAM) while True: data = input("Enter message to send or type 'EXIT': ") bytes = data.encode() UDPSock.sendto(bytes, addr) if data.upper() == "EXIT": break UDPSock.close() os._exit(0)``` What I am working out in the larger schema, is to collect bar-code scans and with each collection return the data back to a desktop PC to be processed and distributed as a periodic data feed. This would be the last component in that process. Being new to Python code, adapting around the calls to the subprocess module will make this challenging to say the least. I appreciate the feedback. Kip...
-
My apologies....
I should have noted when posting the above code that the subprocess issue is first noted when executing line 8.
theargis +=str(sys.argv[1])
Regards!
-
@KipCarter Yes,
subprocess.call("cls")
will not work with pythonista for multiple reasons:cls
is a windows command. Even if you could usesubprocess
, you would have to usesubprocess.call("clear")
instead.- the pythonista shell is not a real shell, but a simple python REPL and I/O shell, so neither
cls
norclear
would have any effect on it.
You can instead use
console.clear()
in pythonista. -
So what is the proper procedure for pip'ing in new modules?
-
Going in a different direction now. I think I will resort to a simple smtp sender and receiver, placing my data in the subject header of each message and extracting it on the other side as it arrives on the pc. I need to setup a lab to make sure this will all work but it should.
Thanks folks!
I still want to know the pip procedure as what I've found documented doesn't seem to work.
Kip...
-
@KipCarter said:
So what is the proper procedure for pip'ing in new modules?
The community has written a custom implementation of
pip
, which is included in StaSh. It works rather well, but does not support any modules depending on C/Fortran code.To install, copy the following:
import requests as r; exec(r.get('https://bit.ly/get-stash').text)
, then paste it in the python REPL (the console) and exute it. Restart pythonista (force quit using double tap). Afterwards, there is a file calledlaunch_stash.py
in themy iphone
(or whatever it is called) directory. Run it. It takes a bit of time, but you should then see a bash-like shell. This shell supportspip install <modulename>
. -
thanks... will get it installed!
-
@bennr01 That did it! Thanks
-
This post is deleted!