Python virtualenv: quick reference

Sun 21 July 2019
Virtual environement (Photo credit: wikipedia)

To isolate python developments, I use virtualenv. This allow me to forget about the specific python version used for each project, avoid interferences with the default python installation and between my projects, is relatively light, and may have other advantages I cannot imagine with my current understanding.

Installation

I won't go into details, it is documented, and I recommend using the default distribution packages.

Creation

The quick reference gives all necessary commands:

  • mkvirtualenv
  • workon
  • deactivate

I recommend using the --always-copy option when creating a virtualenv. It avoid breaking the virtualenv when system upgrades may break symlink to old python version.

One tool I usually need is the add2virtualenv to update PYTHONPATH.

Upgrades

One big advantage of virtualenv is the use of pip without side effects. Inside the virtualenv use it without precaution.

Related articles (or not):

Category: programming Tagged: python tools code