Python Notes and Examples

Virtual Envs

As of the current Python 3, the venv module is in the standard library. You use it like python3 -m venv ....

I use the term “venv” here to mean: (1) the venv module, and (2) as shorthand for “virtual environment”.

(On Debian, with the current Python 3.6, to have the venv module work right you’ll need to first apt install python3-venv.)

Work with venvs like so:

If you’d like to upgrade pip itself (if it’s not already the newest version):

pip install --upgrade pip

See pip help for general help, and pip help <command> for help on a particular command. Pip docs are at

Once you have a venv set up with the packages you want, you can save that config like so:

(foo-env)...$ pip freeze > requirements.txt

then later, with a fresh venv, you can install all of those modules just like you had them before:

(foo-other-env)...$ pip install -r requirements.txt
* * *

Unrelated or don’t-use:

  • pyvenv — just do python3 -m venv instead
  • virtualenv: OLD (Python 2). Subsumed by venv module in Python 3.
  • Legacy: easy_install,, eggs, Distribute, distutils2,
  • pyenv: This is not pyvenv.