Python Libraries

or, Running Python with custom libraries.

While we (the Computer Support Group at CSE) will try to provide Python software applicable to teaching and research, you may wish for Python packages that no one else here wants, or are very new. It may not be convenient for us to provide such packages when it diverts effort from managing the other software here.

In such cases, a useful approach may be to set up your own collection of python libraries. There are probably many ways to do this that would work for you. Provided here are the basic steps for doing it with virtualenv.

Readers who have experience maintaining their own python library sets may help the CSE community by suggesting improvements to this document.

Setting up a "virtualenv"

In your home directory…

$ virtualenv --system-site-packages testpy $ cd testpy/ $ source bin/activate

This sets up directory named "testpy" which holds a virtual python library environment. You may use another name, or create any number of distinctly named environments.

By source-ing the activate script you start to use your new environment and when you run python it should use the libraries you set up in this environment.

Add the latest version of a library (eg: Numpy) like this:

pip install numpy

Or, download and set up a specific version:

pip install numpy==1.8

Large library bundles may take a while to download, compile and install.

Exit the environment by running:

$ deactivate

Home directory space use

Keeping a collection of libraries can use a significant amount of home directory space.
  • If you do not need the virtual environment for long you may create it in /tmp instead of your homedir.
  • If you stop using it, please delete the directory holding the environment.
  • (Class Administrators) If you want other people to use a particular virtualenv please share read access to one you made, rather than asking everyone to create their own copy.

Further information

Last edited by robertd 07/02/2017