omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    5
    15
    20894
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonB
      JonB last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • bennr01
          bennr01 last edited by

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

          1 Reply Last reply Reply Quote 0
          • KipCarter
            KipCarter last edited by

            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...
            bennr01 1 Reply Last reply Reply Quote 0
            • KipCarter
              KipCarter last edited by ccc

              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!

              1 Reply Last reply Reply Quote 0
              • bennr01
                bennr01 @KipCarter last edited by

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

                1 Reply Last reply Reply Quote 0
                • KipCarter
                  KipCarter last edited by

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

                  bennr01 1 Reply Last reply Reply Quote 0
                  • KipCarter
                    KipCarter last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • bennr01
                      bennr01 @KipCarter last edited by

                      @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 1 Reply Last reply Reply Quote 0
                      • KipCarter
                        KipCarter last edited by

                        thanks... will get it installed!

                        1 Reply Last reply Reply Quote 0
                        • KipCarter
                          KipCarter @bennr01 last edited by

                          @bennr01 That did it! Thanks

                          1 Reply Last reply Reply Quote 0
                          • river888a
                            river888a last edited by river888a

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors