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.


    Pypi installer and web server

    Pythonista
    9
    19
    24695
    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.
    • Cicucci
      Cicucci last edited by

      So I thought it would be cool to have a package installer, and have it be callable via a get request from a browser. The following gist is the code I have for the installer:

      https://gist.github.com/anonymous/5243199

      It can be used like:

      from Pypi import Installer
      Installer('Flask', '0.9').install()
      

      It will attempt to download the package (no dependencies though) via Pypi. Keep in mind that Pypi is case sensitive, so make sure the first argument is correct (for instance flask is 'Flask' but bottle is 'bottle'). If you are unsure, check the download URL on Pypi's site.

      It also currently only checks for two types of sources in the tarball. Either a directory with the package name (lowercase) or a single python file with the package name (like bottle.py). This seems to have covered all the packages I have attempted (but maybe not everything).

      Lastly, keep in mind, even though you can install a package, doesn't mean it will work.

      Next, to create a web server, first use the installer to install Flask, Werkzeug, and Jinja2:

      from Pypi import Installer
      Installer('Flask', '0.9').install()
      Installer('Werkzeug', '0.8.3').install()
      Installer('Jinja2', '2.6').install()
      

      Then download this gist which has a demo Flask Server:

      https://gist.github.com/anonymous/5243230

      After running this Flask Server, it will tell you your IP address. In a browser, you can now install packages on your device by going to 'http://IP_ADDRESS:5000/install?package=Flask&version=0.9' while it is running, replacing of course the package and version you want.

      The server is more of a demo, it would probably be better off serving some form instead of using the URL. Also, note that Flask's debug mode does not appear to work, as it complains it is not running on the main thread.

      Let me know if you improve on anything!

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

        Hi there,
        I'm trying to install MySQL-python, Pypi says all went OK, but I can't find the directory anywhere...

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

          Hello, I would ask if new packages installed with Pypi will be exported to xcodeproject for ios app final build to appstore. Thanks.

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

            Sorry it took so long to get back to all of you. Didn't realize this got any responses.

            @tturchi: I looked at MySQL-python. There are two reasons why it doesn't work. 1.) The latest version (1.2.4) uses a zip file rather than a tar.gz. The script assumes a tar file, so I need to make this script more flexible. 2.) Version 1.2.3, which uses a tar file, doesn't have the normally named source file/folder inside it. Since it doesn't see what it expects, it doesn't copy it. I haven't figured out the best way to "discover" all the sources within a Pypi module properly yet.

            @Filippoclaudi: As for a Remove function, I can easily add that. Although, why not just use Pythonista's delete file/folder from its main menu?

            @acescon: This script doesn't "install" pypi packages in the true sense of the word. It just does its best to extract the source files out of Pypi tar files and put them in the main directory for you to be able to import. In other words, it puts the source files in the same area you write your own files. Pythonista doesn't know that you didn't right them. So, if you can import your own code and it works, you should be able to import Pypi sources and have it work.

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

              Great work Cicucci! I look forward to any updates with regards to handling zip files. I, too, am trying to use this to install MySQL-python.

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

                @Tizzy StaSh - https://github.com/ywangd/stash will have pip in 3.0 access to pypi and a package manager.. It's currently in the dev branch. Hanbdles .zip, bz2, gz and will keep track of installed packages.

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

                  Should pypi.py be updated to use Pythonista's site-packages.

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

                    @briarfox I use gitrepo to download gits and I was wondering if there is an easy way to download the dev branch of, for example, stash?

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

                      @ihf I am unfamiliar with git repo. You should be able to change the branch and grab the zip. You could use current stash to download and un archive the Dev.

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

                        I don't believe gitrepo supports branches, but if could be wrong.
                        You would have to modify repolink to point to dev.zip in this case.

                        You could also use
                        https://github.com/jsbain/GitHubGet
                        Which supports branches (simply copy the url after switching branches)

                        Or https://github.com/jsbain/gitview

                        Or, in the case of stash, you could download master, then search for

                        SELFUPDATE_BRANCH=master
                        

                        And change to

                        SELFUPDATE_BRANCH=dev
                        

                        (This is inside the _DEFAULT_RC string)

                        Then call selfupdate from within stash.

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

                          So I was able to download the repo from https://github.com/farcepest/MySQLdb1 using Jon's GitHubGet script, but I'm not sure how to proceed to make it functional...importing MySQLdb still says no such module found. Do I move the whole folder into site-packages?

                          Thanks for all your help everyone!

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

                            Yes, you can move the MySQLdb folder (the one that contains an init.py) into site-packages.

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

                              I moved the folder MySQLdb (from inside MySQLdb1-master folder) containing init.py into site-packages. It now says " no module called _mysql"

                              :(

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

                                @Tizzy Are you dead set on mysql? I've fell in love with mongodb with pymongo.

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

                                  MySQL appears to be written partly in c. So no go on ios.

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

                                    @briarfox I'm not dead set on it, but was just hoping to utilize existing infrastructure that I already have in place.

                                    @JonB what about this connector made specifically for pythonista: https://github.com/tommasoturchi/mysql-connector-pythonista?files=1
                                    Also It seems to lack an init.py...

                                    This guy seems to have gotten it to work, but his instructions are not explicit enough for me to follow... http://omz-forums.appspot.com/pythonista/post/6201194041049088

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

                                      It appears that the repo you pointed to basically implement the instructions already. You should be able to simply copy the files directly into site-packages, without any folder. Or, download into a folder, in which case you will need to sys.path.insert(1,abspath_to_mysqldb_folder) before importing msqldb.

                                      You could also try grabbing stash (dev branch), and run pip install mysql-connector-python. It seems like a lot of what was done in that github repo was because pythonista early versions did not have site-packages... There is no obvious reason the pypi package wouldn't work now, though I haven't tried.

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

                                        To get the dev branch of Stash, simply set SELFUPDATE_BRANCH=dev. This can be set in the .stashrc file, the resource file to stash that is located under stash's installation root (just create the file if not exist).

                                        To install StaSh in the first place, you can either clone the repo or try single file gist installation script @ https://gist.github.com/ywangd/7fbb2c1aa17e8734defd

                                        NOTE: If you do not have an utility to help you read/write dot files, e.g. .stashrc, stash is also here to help. Simply follow these steps from within stash:

                                        • Run selfupdate to get the master branch release
                                        • Run cd $STASH_ROOT
                                        • Run edit -t .stashrc
                                        • Now you can edit the file as a temporary file in Pythonista's builtin editor.
                                        • Once you are done with the file, swipe right to reveal StaSh prompt, enter Y to save the changes.

                                        Please check StaSh GitHub repo for more details.

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

                                          In fact, a very easy way to get the dev branch from within StaSh is to run the following one-line command (without editing any dot files):

                                          SELFUPDATE_BRANCH=dev selfupdate

                                          A bit more explanations on it how works:

                                          • SELFUPDATE_BRANCH is an environment variable to the shell and has default value of master, i.e. selfupdate by default grab the master branch.
                                          • Like any other shells, environment variable can be set as VARNAME=value.
                                          • The above command temporarily override the default value and make selfupdate grab the dev branch.
                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Powered by NodeBB Forums | Contributors