Monday, December 30, 2013

Setup Pip and Virtualenv

In case we need to run python programs that depends on different versions of same libs, we need to create isolated python environment to avoid those libs interfere with each other. There are two tools can help us achieve that, pip and virtualenv.

1. Install pip

Pip is a package manager used to install and manage python packages. On ubuntu (13.04), you could install it via the following command. You could also download it from here.

sudo apt-get install pip

Note: Depending on your python versions, you may want to install pip or pip-3.x package.

2. Install virtualenv

Virtualenv is the tool to create isolated python environments. On ubuntu you could use apt sources to install virtualenv, or you could always use pip to install it.

sudo pip install virtualenv

3. Create a virtual environment

Once you have the tools installed, you could create a virtual environment using the following command.

virtualenv myenv

4. Use a virtual environment

To use the virtualenv, you could activate it by executing the following command. Basically speaking, it prepend the virtualenv/bin to your $PATH environment variable.

cd myenv
. bin/activate

5. Leave a virtual environment

The following command will revert the changes made by the activate script.

deactivate

No comments:

Post a Comment