Python Package Management with virtualenv and pip

Virtualenv creates completely isolated virtual environments having their own python binaries and packages. An alternative is venv which shipps with recent Python versions.


  • each virtual environment has its own python binaries and packages
  • install specific package versions inside each environment
  • no admin rights required to install packages
  • possibility to test an application against several different environments
  • play with the latest unstable version of a package without affecting other users or projects
  • be independent of the versions installed on the system
  • prevent application from breaking because of package or system upgrades


  • some packages may require several minutes to compile and install
  • need to upgrade packages for each virtual environment individually
  • the size of an env folder can easily be a few hundred megabytes

Workflow example

cd MyPythonProject                 # change to your project's directory
virtualenv env                     # create the env folder with a new virtual environment
 # virtualenv -p python3 env       # or create new virtual environment for python3
source env/bin/activate            # adjust shell to use binaries inside env as default
pip install --upgrade pip          # upgrade the package management tool pip
pip install SomePackage            # download and compile a package into local env

Useful pip commands

You can use the package manager pip to install modules inside the virtual environment.

pip list --outdated                # list outdated packages
pip install --user SomePackage     # install package into user's home
pip install SomePackage==1.0.4     # install specific version of package
pip install 'ipython[notebook]'    # install IPython with notebook support
pip freeze > requirements.txt      # output installed packages in requirements format
pip install -r requirements.txt    # install all req packages (like GemFile)
pip uninstall SomePackage          # remove installed package
pip show SomePackage               # list info about installed package, use -f to list files
pip search Query                   # search list of packages

 # install package directly from a git repo
pip install -e git+https://git.repo/some_pkg.git#egg=SomePackage

 # install pywcs 1.11 from source
pip install

 # force pip 1.5 to install latest matplotlib whose files are note hosted on PyPI
pip install matplotlib==1.3.1 --allow-external matplotlib --allow-unverified matplotlib

 # install package into subfolder of current path
pip install SomePackage -t localpip
 # the package can then be imported from python by adapting the search path, e.g
    import sys
    import SomePackage