Coming from JavaScript, Python environemnts and package management was an enigma for a while. Fortunately, venv makes it easy to create virtual environments for projects. See the instructions below based on the Streamlit Docs.

  1. Create a new virtual environment in that folder and activate that environment:

    python -m venv .venv

When you run the command above, a directory called .venv will appear in myproject/. This directory is where your virtual environment and its dependencies are installed.

  1. Any time you want to use the new environment, you first need to go to your project folder (where the .venv directory lives) and run:

    source .venv/bin/activate

  2. When you’re done using this environment, type deactivate to return to your normal shell.