blog-image

Apr 15, 2021

8 min read

Simplifying Python 3 setup using venv

Written by

Vippy The VPS

Dependency hell

Without virtual environments, working with Python is a nightmare! In case of Ubuntu, the base operating system comes with Python preinstalled, and you might think that that\'s a nice thing. Except, that version of Python is old and pip is not even installed. So you install pip only to find out that it is detecting and trying to update Python programs that are part of the base operating system and are supposed to be managed by your operating system's package manager.

This same pattern of unavailability and conflicts gets worse over time as you start working on multiple Python projects. Dependencies of one might conflict with the other. You may require a specific version of request package for one project and a different version for another, and on and on. This frustration is well-depicted in this XKCD Comic:

Python Dependency Hell

This post tries to address all these problems, and then some more. Obviously, most of this is aimmed at Linux users, and is tested on a Ubuntu 20.04 LTS server, but the principles can be generalized for macOS and Windows 10 too.

Goals

The goal is to achieve the following with regards to our Python 3 environment:

  • Isolating it from the broader Operating system.
  • Making it easy to configure and backup
  • Making it easily upgradable
  • Using methods recommended by the Official Documentation

We will be using venv module which is the recommended way to create virtual environments

Python venv to the rescue

In Python 3.6 the problem of managing multiple dependencies has received the cleanest resolution -- Virtual Environments or venv. In my opinion, this has rendered a lot of third party options like conda, pyenv, etc less relevant, if not completely redundant.

venv is an official Python module that is meant for running an isolated Python environment. This isolated environment can include Python interpreter, pip, and setuptools. All these

Continue reading this article
by subscribing to our newsletter.
Subscribe now

A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.

If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.