
- Isolates a project’s dependencies from the system Python and from other projects.
- Lets different projects use different package or Python versions (for example, one project can use OpenCV 4.x while another uses 3.x). See OpenCV: https://opencv.org/
- Makes projects portable: export dependencies with a requirements file and others can recreate the environment exactly using
pip install -r requirements.txt. See pip requirements docs: https://pip.pypa.io/en/stable/topics/requirements-files/
- Use editor extensions to speed development and reduce boilerplate. Popular choices include GitHub Copilot, GitHub Copilot Chat, Blackbox, and Tabnine.
- When you enable GitHub Copilot you will authenticate through GitHub.
- You can toggle auto-complete and other extension features depending on how much in-editor assistance you want.
imageoptimizer) and run:
- The venv folder can be named anything (
image-optimizer,venv,myenv). Many teams usevenvfor consistency and to simplify.gitignorerules. - The command above creates a
venvdirectory containing an isolated Python interpreter,pip, and site-packages for that environment.
After activation your prompt typically shows the environment name:
python and pip commands refer to the virtual environment’s binaries; you no longer need to run python3 explicitly.
What the venv folder contains (overview)
Inside the created venv directory you will commonly find:
bin/(macOS/Linux) orScripts\(Windows) — executables and activation scriptsinclude/— C headers used when compiling extension moduleslib/orLib\— installed Python packagespyvenv.cfg— configuration for the virtual environment
- Install packages inside the activated venv:
- Freeze the current environment to a
requirements.txtfor reproducibility:
- Recreate the environment elsewhere:
Add your virtual environment directory (for example,
venv/) to .gitignore so installed packages are not committed to source control.Do not commit your virtual environment directory to Git. Instead commit
requirements.txt (or a lock file) so collaborators can recreate the environment reliably.- A Python virtual environment isolates dependencies per project so multiple projects can use different package or Python versions.
- Create a venv with
python3 -m venv venv, activate it with the proper activation script for your shell/OS, then install packages usingpip. - Export dependencies with
pip freeze > requirements.txtand recreate environments withpip install -r requirements.txt. - Editor extensions (e.g., GitHub Copilot, Tabnine) can speed development but do not change how virtual environments work.
- Python venv documentation: https://docs.python.org/3/library/venv.html
- pip requirements files: https://pip.pypa.io/en/stable/topics/requirements-files/
- VS Code: https://code.visualstudio.com/
- OpenCV: https://opencv.org/