Forum Archive

Can't pip install subprocess

KipCarter

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!

ccc

Python comes with subprocess builtin. You do not need to install it. Just import subprocess In your Python code and you are off to the races.

JonB

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.

JonB

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.

JonB

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.

bennr01

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 called monkeylord, 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 run monkeylord enable subprocess, then run python <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 like pip or echo. 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)..

KipCarter

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...

KipCarter

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!

bennr01

@KipCarter Yes, subprocess.call("cls") will not work with pythonista for multiple reasons:

  1. cls is a windows command. Even if you could use subprocess, you would have to use subprocess.call("clear") instead.
  2. the pythonista shell is not a real shell, but a simple python REPL and I/O shell, so neither cls nor clear would have any effect on it.

You can instead use console.clear() in pythonista.

KipCarter

So what is the proper procedure for pip'ing in new modules?

KipCarter

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...

bennr01

@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 called launch_stash.py in the my 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 supports pip install <modulename>.

KipCarter

thanks... will get it installed!

KipCarter

@bennr01 That did it! Thanks

river888a

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 LiteBlue.