Difference between revisions of "Python virtual environment"

From ScientificComputing
Jump to: navigation, search
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
__NOTOC__
 +
{{back_to_tutorials}}
 +
 
This example shows how to create a Python virtual environment.
 
This example shows how to create a Python virtual environment.
First, switch to the new software stack
+
 
 +
== Load modules ==
 +
Switch to the new software stack
 
  $ env2lmod
 
  $ env2lmod
  
Line 11: Line 16:
 
  $ module load gcc/6.3.0 python/3.8.5
 
  $ module load gcc/6.3.0 python/3.8.5
  
Create a Python virtual environment
+
== 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
 
  $ python -m venv --system-site-packages myenv
Line 30: Line 36:
  
 
  (myenv)$ deactivate
 
  (myenv)$ deactivate
 +
 +
{{back_to_tutorials}}

Latest revision as of 11:06, 16 June 2021

< Examples

This example shows how to create a Python virtual environment.

Load modules

Switch to the new software stack

$ env2lmod

or, set your default software stack to the new software stack

$ set_software_stack.sh new

Load a Python module

$ module load gcc/6.3.0 python/3.8.5

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