How to install python packages without root privileges?

Question:

I am using numpyscipy / pynest to do some research computing on Mac OS X. For performance, we rent a 400-node cluster (with Linux) from our university so that the tasks could be done parallel. The problem is that we are NOT allowed to install any extra packages on the cluster (no sudo or any installation tool), they only provide the raw python itself.

How can I run my scripts on the cluster then? Is there any way to integrate the modules (numpy and scipy also have some compiled binaries I think) so that it could be interpreted and executed without installing packages?

Asked By: Skyler

||

Answers:

You could create a virtual environment through the virtualenv package.

This creates a folder (say venv) with a new copy of the Python executable and a new site-packages directory, into which you can “install” any number of packages without needing any kind of administrative access at all. Thus, activating the environment through source venv/bin/activate will give Python an environment that’s equivalent to having those packages installed.

I know this works for SGE clusters, although how the virtual environment is activated might depend on your cluster’s configuration.

You can try installing virtualenv on your cluster within your own site-packages directory using the following steps:

  1. Download virtualenv from here, put it on your cluster

  2. Install it using setup.py to a specific, local directory to serve as your own site-packages:

    python setup.py build
    python setup.py install --install-base /path/to/local-site-packages
    
  3. Add that directory to your PYTHONPATH:

    export PYTHONPATH="/path/to/local-site-packages:${PYTHONPATH}"
    
  4. Create a virtualenv:

    virtualenv venv
    
Answered By: David Robinson

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

Answered By: Colonel Panic

You can import a module from an arbitrary path by calling:

sys.path.append()

Answered By: john graham

The Python Distribution Anaconda solves many of the issues discussed in this questions. Anaconda does not require Admin or root access and is able to install to your home directory. Anaconda comes with many of the packages in question (scipy, numpy, sklearn, etc…) as well as the conda installer to install additional packages should additional ones be necessary.

It can be downloaded from https://www.continuum.io/downloads

Answered By: Brian Cain
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.