Venv
- File size
- 3.8KB
- Lines of code
- 92
Venv
Virtual environments.
This document discusses venvs specifically within the context of Python.
What is a venv?
Python-native module that installs a directory comprised of the following files to your project repository.
- Python interpreter
- Set of installed packages
- Scripts to activate and deactivate the environment
Why use a venv?
Create and reproduce isolated Python environments within the local project, allowing for fuss-free management of project-specific dependencies without interfering with system-wide Python installations.
How do I use a venv?
$ python3 -m venv venv
$ venv\Scripts\activate # for windows systems
$ source venv/bin/activate # for unix/linux systems
$ pip install package_name # install all your packages
$ deactivate # close the virtual environment
You can also make your project reproducible with a requirements.txt.
$ pip3 freeze > requirements.txt
A common question
Do I commit my venv to git?
No. Please specify venv within your .gitignore.
Should I use a venv if I'm not being forced to?
Yes. It is widely used in production.
More on
- Python and Virtual Environments by Princeton Department of Computer Science
- Create a Virtual Environment with Python by loic-nazaries on Github
- venv — Creation of virtual environments Python official docs
- How can I set up a virtual environment for Python in Visual Studio Code? on Stack Overflow
- direnv Github Repository