Virtual Environment (venv)


PowerShell & Bash

  1. 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
  2. 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
  3. 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.

  1. press Ctrl + P or Cmd + P to open the command palette.

  2. Enter settings.json and open it. This will create a new settings.json file in your projects folder.

  3. Add the follow code and save Ctrl + S or Cmd + 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 ↑