Member-only story

Python; how and why you should use venv

Colt Gainey
4 min readAug 8, 2023

--

Python, by itself, is powerful. However, to unlock its full potential, one only needs to scan the various free libraries on PyPI to see how much is possible with a sprinkling of pip packages. A few pip installs will likely work fine:

pip install <package> <package>

And you’ll go on your merry way. However, weeks later, when you start working on something completely separate from that previous project, you’ll again go to install packages:

pip install <package>

And you may encounter any number of issues related to conflicting dependencies. The problem is that while your code for these two projects is isolated:

/projects/
awesome_project_1/
main.py
awesome_project_2/
main.py

Your dependencies for these two are not. This is easily solvable however, using a handy tool called ‘venv’, which allows you to create a virtual environment to run your Python code, which can be activated or deactivated at any time. This, used in conjunction with a `requirements.txt` file, can easily allow you to share your code with others along with the dependencies necessary to run it.

Installations

Let’s get started by installing the `venv` package.

pip install virtualenv

Easy enough, we now have virtualenv on our machine.

Creating Virtual Environment

--

--

Colt Gainey
Colt Gainey

Written by Colt Gainey

Engineer, writer, and climber.

Responses (1)