Python virtual environment

From ScientificComputing
Revision as of 07:59, 10 July 2024 by Sfux (talk | contribs) (Create a Python virtual environment)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

< Examples

This example shows how to create a Python virtual environment.

Load modules

Load a Python module

$ module load stack/2024-06 python/3.11.6

Create a Python virtual environment

The option --system-site-packages includes Python packages from host Python also in the virtual environment.

$ python -m venv --system-site-packages myenv

Activate the virtual environment

$ source myenv/bin/activate

Check the python packages included in this environment

(myenv)$ pip3 list

You can install new packages inside this environment

(myenv)$ pip3 install --upgrade pip

Deactivate the Python virtual environment

(myenv)$ deactivate

< Examples