-
Notifications
You must be signed in to change notification settings - Fork 0
Python Virtual Environment Primer
This guide helps you create and activate an isolated Python environment using venv on Windows, macOS, and Linux.
- Python 3.x installed (preferably 3.6+)
-
venvmodule is included by default with Python 3.3+ - Verify your installation:
python --version # or python3 --version
To create a virtual environment (named scicomp_env, though you can choose any name), open a terminal or command prompt in your project directory and run the following command:
python -m venv scicomp_envpython3 -m venv scicomp_envThis creates a subdirectory called scicomp_env/ that contains the isolated Python interpreter and dependencies.
scicomp_env\Scripts\activatescicomp_env\Scripts\Activate.ps1Note: If you get an execution policy error in PowerShell, run:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
source scicomp_env/bin/activateWhen activated, your shell prompt will prefix with (scicomp_env).
Once the environment is active:
-
Install packages with
pip, e.g.,HamLorenz:pip install hamlorenz
-
These packages will be isolated to the virtual environment.
When you're done working in the virtual environment, deactivate it:
deactivatepip listpip freeze > requirements.txtpip install -r requirements.txt- You can safely delete the
scicomp_env/folder to remove the environment. - IDEs like VS Code automatically detect and use the
scicomp_envif placed in your project folder. - For project-based work, it is good practice to include the
scicomp_env/folder in your.gitignore.
HamLorenz is developed under BSD 2-Clause License, Copyright(c) 2025 cristel.chandre@cnrs.fr