Python Environment Examples and Gotchas: Pip, Virtualenvs, etc

Last updated:

If you need to work with python you'll sooner or later bump into one of these terms so they will be defined here for future reference.

  • pip

Package installer for Python. Kind of like gem for ruby.

  • virtualenv

A tool to help you keep multiple versions of python (and separate python packages) for each of your projects. Think of rvm and gemsets for ruby.

Create and activate a virtualenv:

$ virtualenv <your-env-name>
$ . <your-env-name>/bin/activate

(to deactivate it, just run deactivate from anywhere in your system

Create a virtualenv with system packages

To include system packages (i.e. those you have installed with apt-get or the like) use --system-site-packages

$ virtualenv <your-env-name> --system-site-packages

Create a virtualenv using Python 3 interpreter

$ virtualenv -p python3 <your-env-name>

Install a package for the currently activated virtualenv

(my-env)$ pip install <package-name>

Install a package globally

$ sudo pip install <package-name>


Dialogue & Discussion