Virtual Environment (venv)
PowerShell & Bash
-
This command creates a new folder called viron (you can name it anything) containing a clean Python environment.
POWERSHELL
Copied!
python -m venv viron
BASH
Copied!
python3 -m venv viron
-
Activate the virtual environment. This changes the shell prompt to show (viron) indicating the venv is active.
POWERSHELL
Copied!
.\viron\Scripts\Activate
BASH
Copied!
source viron/bin/activate
-
Deactivate the virtual environment. Returns you to your normal system environment.
POWERSHELL
Copied!
deactivate
BASH
Copied!
deactivate
You can also enable automatic environment activation in VS Code when opening a new terminal.
-
press
Ctrl + P
orCmd + P
to open the command palette. -
Enter
settings.json
and open it. This will create a newsettings.json
file in your projects folder. -
Add the follow code and save
Ctrl + S
orCmd + S
.JSON
Copied!
"python.terminal.activateEnvironment": true
Note: Sometimes you may still need to manually reset the terminal, and the (viron) label might not appear in the prompt even though the environment is activated.
Top ↑