Install Python modules to a different directory
Saturday, February 22nd, 2014There are times that I have wanted to install some Python module on a system where I did not have access to do so.
When you do not have permission to write into the standard library directories you
may need to run the “python setup.py install” command with the additional option of
--home=<Some other directory>
make sure that this base directory has a lib/python directory within it and that you have
exported the PYTHONPATH variable to contain this directory.
Then simply run the command “python setup.py install –home=<Some other directory>” and your libs will
be installed.
Then you will need to make sure that your PYTHONPATH environment variable is always available
to whatever runs your scripts.
As an alternative to the PYTHONPATH, you can use the following within your scripts to target a non-standard python module directory:
import sys sys.path.append("/path/to/the/module/directory") ## import any modules you have in your own directory
Using the method in the script allows you to make the scripts available to other users that may not have the PYTHONPATH setup.
Tags: Python