A Python virtual environment gives a project its own set of installed packages. Think of it as a separate toolbox: a chatbot can use one version of a package while another project uses a different version, without the two installations conflicting. Create an environment before installing a project’s packages. section 6.1
Figure 6.1 Without virtual environments (right), all projects share the same packages, which can cause version conflicts. With virtual environments (left), each project gets its own isolated set of packages, keeping everything clean and conflict-free.
Compare separate project environments with a shared set of packages. section 6.1
An environment is a folder on disk. On macOS, its bin folder contains its Python executable and pip installer, while installed packages live under lib. The pyvenv.cfg file identifies the directory as a virtual environment. section 6.2.4
Create and use an environment
In a terminal, move into your project folder, then run: python3.13 -m venv .venv source .venv/bin/activate pip install requests The first command uses Python’s built-in venv module to create a folder named .venv. Use .venv rather than .env, which is often used for secrets and configuration. Creation normally returns to the prompt without output; wait for it to finish before activating. On macOS, activation changes the terminal’s settings so Python and pip use the environment. A (.venv) prefix in the prompt signals that it is active. Run deactivate when you are finished. section 6.2.2 section 6.2.3 section 6.3.1 section 6.7
To share or rebuild the setup, run pip freeze > requirements.txt while the environment is active. This records installed packages and exact versions. Share requirements.txt rather than the .venv folder; in a newly created and activated environment, run pip install -r requirements.txt to install from the file. section 6.7 section 6.6
Check which environment you are using
If Python reports that it cannot find Streamlit, it may be running outside the environment where Streamlit was installed. Activate the project’s environment, then run which python3 and python3 -m pip list | grep streamlit to check the interpreter path and package. If Streamlit is missing, install it with pip install streamlit. Run the app with python3 -m streamlit run app.py to use the same Python interpreter. section 15.1.5
Try comparing two projects: install requests in one environment and flask in the other. Activate each in turn and run pip list to see how their packages differ. section 6.6






