People have access to servers as normal users (jailed actually), and they're advised - at the moment - to download whatever python packages they need, setup.py build them, then add their location to sys.path.

Without virutalenv, is there a way to make easy_install and pip install packages to a directory (in $PYTHONPATH) inside of ~?

Alternatively, can you set up a virtualenv that is always active for a given user, both in the shell and with repsect to Apache and mod_wsgi?

In short, how do you best get around the permissions problem in installing site packages?


To get virtualenv available in shell automatically you should source its bin/activate script every time the user logs in. You can do this along with creating default virtualenv environment when the user is created. Or you can just add path to the virtualenv's python interpreter to the $PATH variable right in the user's .bash_login, .zshrc or whatever else.

Virtualenv, when activated, modifies two environment variables. First, it will add {virtualenv}/bin to your $PATH, and second, it will define $VIRTUAL_ENV variable telling where exactly virtualenv is set up. So you may try to mimic its behavior in Apache by setting these variables. In the end you should use virtualenv's python interpreter downloaded with virtualenv which has all necessary paths set up.

mod_wsgi in its hand has some configuration options which can help you with this. It should be sufficient to use WSGIPythonPath. You might consider using WSGIPythonEggs as well.

However note that you should protect the initial setup from being modified by user but accessible by user running apache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.