Unable to install Python without sudo access

How can I install to a path under my home directory?

mkdir /home/masi/.local

cd Python-2.6.1
make clean
./configure --prefix=/home/masi/.local
make
make install

Then run using:

/home/masi/.local/bin/python

Similarly if you have scripts (eg. CGI) that require your own user version of Python you have to tell them explicitly:

#!/home/masi/.local/bin/python

instead of using the default system Python which “#!/usr/bin/env python” will choose.

You can alter your PATH setting to make just typing “python” from the console run that version, but it won’t help for web apps being run under a different user.

If you compile something that links to Python (eg. mod_wsgi) you have to tell it where to find your Python or it will use the system one instead. This is often done something like:

./configure --prefix=/home/masi/.local --with-python=/home/masi/.local

For other setup.py-based extensions like MySQLdb you simply have to run the setup.py script with the correct version of Python:

/home/masi/.local/bin/python setup.py install

Leave a Comment