Thursday, February 5, 2015

installing python libraries without admin user


Installing python libraries/packages is not very complex issues. Mostly, packages are available in Python Package Index (PyPi) and can be installed using pip or easy_install tools. for example see the following commands.

pip install package e.g.
pip install paramiko

However, in the standard installation procedure, a sudo or root permission is required as the installation procedure attempts to write library files in python's lib directory managed by root. Thus, we run into permission issues.

On a system without admin permission, we can still install python libs by following this procedure. We will use the same as above, which will fail to complete due to non-sudo user. But that is fine.

pip install paramiko

this will download the paramiko files in a directory displayed in command output on terminal.

Go to this directory and run the command 'python setup.sh install —prefix WRITEABLE_PATH'.

where WRITEABLE_PATH is the directory where you can write/create files.
Before running this command, make sure that the WRITEABLE_PATH exists and is included in PYTHONPATH variable.

export PYTHONPATH=WRITEABLE_PATH:$PYTHONPATH

now run the python setup.py install —prefix WRITETABLE_PATH

the modules/packages will be built and placed in this directory. Since this directory is part of your PYTHONPATH variable, you will be able to access these packages in your python code.

NOTE: you always need to set the PYTHONPATH to this directory before executing your python code.

No comments: