How do I create a Python virtual environment?

  1. Create a Python virtual environment using the venv module by running:

    python -m venv --system-site-packages NAME
    

    Replace NAME with the name you want to give to your virtual environment.

  2. Activate the virtual environment by running:

    . NAME/bin/activate
    

    Replace NAME with the name you gave your virtual environment in the previous step.

    Python packages you install in your virtual environment are isolated from the base environment and other virtual environments.