Skip to content

How to Set up Python Virtual Environments

DebRez edited this page Jun 27, 2016 · 12 revisions

IN DEVELOPMENT - NOT READY FOR USE

Setting up a Python Virtual Environment is helpful for several reasons. An isolated environment avoids conflicts with Python packages used by other programs on the users system. Also, virtual environments allow the user to choose which version of Python they want to run on and to easily switch between versions.

Install Python

It probably is already there, but Django 1.8 (needed by mtt console) does not support all versions. Check to see which versions of Python are available on your system. You will need Python version 2.7 or Python 3.3+ to run the console.

Check for Required Software

MTT requires the following packages, or their equivalents for your system, to work with Python 2 or 3:

  • libpq-dev
  • python-dev
  • python3-dev
  • python-psycopg2
  • python3-psycopg2
  • automake
  • libtool
  • flex
  • python-pip

Install the following packages using: $ pip install

  • future
  • virtualenv
  • virtualenvwrapper
Edit Your Shell Script for VirtualEnv

Add the following lines to your shell script:

source /usr/local/virtualenvwrapper.sh export WORKON_HOME=$HOME/virtualenvs

Create Your Virtual Environment for MTT

Your specific paths may vary.

To create your new environment enter:

$ mkvirtualenv -r pyenv.txt --python=/usr/bin/(python of your choice) yourEnvName

It is not necessary to include --python=. The default is the systems Python (type: python -V to check your default version).

Enter the Virtual Environment

To see a list of available virtual environments use:

$ workon

To switch between environments type:

$ workon yourEnvName

To exit a virtual environment type:

$ deactivate

Before making a new virtual environment be sure to deactivate the environment you are currently in as shown above.

Clone this wiki locally