Installing libraries when running multiple versions of Python

124 views Asked by At

This may have been asked before but I wasn't able to find any information on it. If I am running multiple versions of Python, namely Python 2.7 and Python 3.3.5, how do I install libraries for a particular version among the two?

1

There are 1 answers

3
bagrat On

You would rather consider using Virtual Environments for Python. It will let you create separate and independent Python environments, for different version of Python, as well as packages.

I would also recommend this package, which just wraps virutalenv and adds handy functionality.

So concretely for your situation, you may create two environments for Python 2.7 and 3.3.5, and install the required libraries for each virtualenv. Here is a brief example of what you will have to do:

$ mkvirtualenv venv27  # This will create and activate virtualenv for Python 2.7
$ deactivate  # ...to deactivate venv27
$ mkvirtualenv venv33 -p /usr/bin/python3.3  # same for Python 3.3.5
$ deactivate

Note the -p option, which specifies the Python interpreter for that virtual environment.

After creating your virtual environment, you can start working on them using the workon utility:

$ workon venv27  # or venv33