Paul's Python CoursePPC

Virtual environments

Not met yet

A virtual environment is a folder (by habit .venv, inside the project) holding that project's own Python packages. Make it once with python -m venv .venv, switch it on in each new terminal (source .venv/bin/activate, or .venv\Scripts\Activate.ps1 on Windows), and pip install then installs into it alone. The project lists what it needs in requirements.txt, so the folder itself is never shared: anyone can rebuild it.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks a package installed in one virtual environment can be imported from any project.
  • Thinks a virtual environment stays switched on in a new terminal window.
  • Thinks the .venv folder should be copied or committed along with the project's code.

Where it comes up