Skip to content Skip to sidebar Skip to footer

How To Install Python Package In A Specific Directory

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 dir, o

Solution 1:

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

Solution 2:

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

Solution 3:

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.

Solution 4:

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.

Post a Comment for "How To Install Python Package In A Specific Directory"