You are here: Download Web>LinuxInstallation>PythonVirtualenv (15 May 2010)

Installing Python Packages in a Virtual Environment

On some Linux distributions, like Debian, system-wide installation of Python packages using easy_install interfers with the built-in packaging system (aptitude). In addition, the packages installed system-wide might get updated to versions incompatible with the current state of the OPUS/UrbanSim source. Or, the other way round, you might break other software by editing source files from system-wide packages, as required for SixtyFourBitMachines. Last but not least, local policy might prohibit system-wide installation of packages. A safe and simple way to avoid all of this consists of using virtualenv, a builder for isolated Python environments.

Get virtualenv using aptitude:

$ sudo apt-get install python-virtualenv

or easy_install:

$ easy_install virtualenv

Then, create your virtual Python environment (VE) for OPUS/UrbanSim:

$ python2.5 `which virtualenv` ~/opus-env

This creates a new directory named opus-env in your home directory and stores some required files, including the Python interpreter that was used to launch virtualenv. By calling virtualenv with python2.5, we ensure that it will use Python in version 2.5 -- this will not change even if a newer version of Python is installed system-wide. Change this to your preferred version of Python.

Activate the newly created VE with the following command:

$ source ~/opus-env/bin/activate

Note that the command line prompt is prefixed with the environment name after execution of the comnmand.

Now, invoking Python starts the Python interpreter in your VE, and packages installed there are preferred over system-wide packages. The behavior of easy_install also changes: Instead of attempting a system-wide installation, all packages are installed into our VE. Verify this by querying the location of the python and easy_install executables in the PATH:

(opus-env) $ which python
/home/[username]/opus-env/bin/python
(opus-env) $ which easy_install
/home/[username]/opus-env/bin/easy_install

If the command prints paths under /usr/bin, the VE is not active.

Proceed as above to install all required and optional packages into your VE. This way, you ensure that you always can run OPUS/UrbanSim without needing to worry about external changes.

Note that you also have to tell eclipse to use Python from your VE, cf. ConfiguringEclipse. When running simulations or starting the GUI, do so from a shell with activated VE.

-- Main.KirillMueller - 28 Jan 2010

Topic revision: r3 - 15 May 2010 - 14:35:44 - KirillMueller
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback