How to install and uninstall Python package from source

A lot of Python packages are only available as source code.

Install

To install such a Python package, use its setup.py file:

$ sudo python setup.py install

This will install the Python files to a central location such as /usr/local/lib. If you do not have such permissions or want to install to a user-local location then try this:

  • Create a directory, say /home/joe/python_libs/lib/python in your home directory to host local Python packages.
  • Set the above path in the PYTHONPATH environment variable.
  • Install the package by passing the above path to the --home parameter:
$ python setup.py install --home /home/joe/python_libs

Uninstall

To uninstall a package is tricky.

One solution is to find out where the files were installed and then use that list to remove those files:

$ sudo python setup.py install --record install-files.txt
$ cat install-files.txt | sudo xargs rm -rf

Another solution is to just locate the installation directory, like /usr/local/lib/python2.7/dist-packages for example and delete the directory of the package.

Tried with: Python 2.7.6 and Ubuntu 14.04

Advertisements

One thought on “How to install and uninstall Python package from source”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s