This cheatsheet is addressed to Polytechnique students I met during IT support sessions.

From Princeton university website :

Virtual environments let you have a stable, reproducible, and portable environment. You are in control of which packages versions are installed and when they are upgraded.

It is useful when switching between projects of different classes, each of them might be requiring different dependencies versions. You can check them on the school’s JupyterHub.

To create the virtual environment, at the root of the project (might be python3) :

python -m venv venv

You need to activate the environment every time you want to use it.

Linux & macOSWindows
source venv/bin/activate.\venv\Scripts\activate

Now, venv should be written somewhere on your command line prompt.

Once your environment is active you can use pip normally (pip install, …). With pip , you can also :

  • list dependencies currently installed :
    pip freeze > requirements.txt
  • install dependencies from a requirements.txt file :
    pip install -r requirements.txt