How to install python modules without root access?
In most situations the best solution is to rely on the so-called "user site" location (see the PEP for details) by running:
pip install --user package_name
Below is a more "manual" way from my original answer, you do not need to read it if the above solution works for you.
With easy_install you can do:
easy_install --prefix=$HOME/local package_name
which will install into
$HOME/local/lib/pythonX.Y/site-packages
(the 'local' folder is a typical name many people use, but of course you may specify any folder you have permissions to write into).
You will need to manually create
$HOME/local/lib/pythonX.Y/site-packages
and add it to your PYTHONPATH
environment variable (otherwise easy_install will complain -- btw run the command above once to find the correct value for X.Y).
If you are not using easy_install
, look for a prefix option, most install scripts let you specify one.
With pip you can use:
pip install --install-option="--prefix=$HOME/local" package_name
How to install python packages without root privileges?
You don't need root privileges to install packages in your home directory. You can do that with a command such as
pip install --user numpy
or from source
python setup.py install --user
See https://stackoverflow.com/a/7143496/284795
The first alternative is much more convenient, so if the server doesn't have pip
or easy_install
, you should politely ask the admins to add it, explaining the benefit to them (they won't be bothered anymore by requests for individual packages).
Install python package without root access
If virtualenv is installed on the server, you can create a virtual environment:
virtualenv your_env_name
Then activate it:
source your_env_name/bin/activate
Then install all your desired packages via
pip install packagename
However, if virtualenv is not installed yet, you should take a look at this thread where the same question has been answered already.
It is still better to use a separate virtualenv for each of your projects, because then you can easily export your dependencies using
pip freeze > requirements.txt
You could add this requirements.txt to your version control, and later, if you want to install your project on another machine, you can install all dependencies at once without messing with version numbers etc:
pip install -r requirements.txt
Simple way to install a setuptools python module without root access?
Use the --prefix
option like:
python setup.py install --prefix ~/.local
EDIT:
This is similar to using --user
, which uses the user specific site-package (defined to be ~/.local on *nix as per PEP 370) automatically.
installing pip without being root failing
echo "export PATH=~/.local/bin:$PATH" >> ~/.bashrc
You want bash to use pip from ~/.local/bin
, not from /usr/local/bin
. So place .local
before every other entry in your path.
How to install a Python module without root, pip, setuptools, or easy_install
Add build/lib/
to PYTHONPATH
.
Some Confusion about easy_install without Root Access
It looks like there are multiple versions of pip
floating around (cf pip: dealing with multiple Python versions? ). Try installing pip using a specific version of easy_install
. For example, this gave me a pip2.7
walnut.39$ easy_install-2.7 -U --user pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 1.5.6
Processing pip-1.5.6-py2.7.egg
pip 1.5.6 is already the active version in easy-install.pth
Installing pip script to /u/walnut/h1/grad/rcompton/.local/bin
Installing pip2.7 script to /u/walnut/h1/grad/rcompton/.local/bin
Installing pip2 script to /u/walnut/h1/grad/rcompton/.local/bin
Using /net/walnut/h1/grad/rcompton/.local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
walnut.40$
Then use pip2.7
walnut.40$ pip2.7 install --user networkx
Also, for non-root package installations, I've got the follow lines in my .bashrc:
export PYTHONPATH=$PYTHONPATH:$HOME/.local/lib/python2.7/site-packages
export PATH=$PATH:~/.local/bin
Related Topics
R and Python in One Jupyter Notebook
R Expand.Grid() Function in Python
How to Take a Screenshot/Image of a Website Using Python
How to Make Sure If Some HTML Elements Are Loaded for Selenium + Python
Why Are Scripting Languages (E.G. Perl, Python, and Ruby) Not Suitable as Shell Languages
Parallel Processing from a Command Queue on Linux (Bash, Python, Ruby... Whatever)
Move Files from One Directory to Another with Paramiko
Detect New or Modified Files with Python
How to Use Python2.7 Pip Instead of Default Pip
How to Use the Same Python Virtualenv on Both Windows and Linux
What Is Different Between Makedirs and Mkdir of Os
Boto3 Client Noregionerror: You Must Specify a Region Error Only Sometimes
Authenticate from Linux to Windows SQL Server with Pyodbc
Apt-Get Install for Different Python Versions