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.

  1. Python interpreter
  2. Set of installed packages
  3. 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