How to install python package in a specific directory

后端 未结 4 868
猫巷女王i
猫巷女王i 2021-01-24 04:02

I\'m developing a twitter app on google appengine - for that I want to use the Twython library. I tried installing it using pip - but it either installs it in the main python di

相关标签:
4条回答
  • 2021-01-24 04:24

    If you put the module files in a directory, for example external_modules/, and then use sys.path.insert(0, 'external_modules') you can include the module as it would be an internal module.

    You would have to call sys.path.insert before the first import of the module. Example: If you placed a "module.pyd" in external_modules/ and want to include it with import module, then place the sys.path.insert before.

    The sys.path.insert() is an app-wide call, so you have to call it only once. It would be the best to place it in the main file, before any other imports (except import sys of course).

    0 讨论(0)
  • 2021-01-24 04:32

    If you're installing a package using pip, try this:

    Install a Python package into a different directory using pip?

    I personally needed libraries that I was just using out of git repos. I just symlinked those libraries instead of installing them. But in that case, I had to manually symlink all the dependencies too.

    0 讨论(0)
  • 2021-01-24 04:37

    Use virtual environment and virtual environment wrapper , you dont have to use the wrapper but use it for simplicity..

    https://pypi.python.org/pypi/virtualenv

    0 讨论(0)
  • 2021-01-24 04:50

    You could use gaenv (package manager I built for app engine). It only creates symlinks and follows the pip requirements.txt format. You can install & use like:

    pip install gaenv
    # create requirements.txt -> twython
    pip install -r requirements.txt
    gaenv
    

    This creates symlinks to gaenv_lib/ of all required libraries. Then will ask to add the import statement.

    0 讨论(0)
提交回复
热议问题