Python 3 cheatsheet

Python 3: Virtual environments

4 common Python 3 tasks.

Create a virtual environment

Create an isolated environment in the .venv folder.

python3 -m venv .venv

Activate it

Use the environment's Python and packages in this shell. Once active, python and pip refer to the environment, so the pip commands below use python. On Windows run .venv\Scripts\activate.

source .venv/bin/activate

Deactivate it

Leave the virtual environment.

deactivate

Upgrade pip

Upgrade pip inside the active virtual environment.

python -m pip install --upgrade pip

Was this page helpful?