Python virtual environment

From ScientificComputing
Jump to: navigation, search

< Examples

This example shows how to create a Python virtual environment.

Load modules

Load a Python module

$ module load gcc/8.2.0 python/3.11.2

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)$ pip list

You can install new packages inside this environment

(myenv)$ pip install --upgrade pip

Deactivate the Python virtual environment

(myenv)$ deactivate

< Examples