Manage packages with venv in Python

Wednesday, Apr 29, 2020
Python Tools

While working on a project, most likely we will come across a problem where a new package is needed, an old one needs updated or a new one needs downgraded. Doing so using the base package repository will get us going but eventually will come to haunt us - either we have already broken some other project or future changes for a new project will break the current one.

Solution: Use virtual environments

  1. In your project directory, create a virtual environment:
>python3 -m venv <envName>
  1. Activate virtual environment(note that command prompt will indicate that you are in the virtual envionment):
source <envName>/bin/activate
  1. Any package updates now will only affect this virtual environment. Start working on the project. When you are done, deactivate the virtual environment:
  1. Whenever you want to work on this project, repeat steps 2 and 3.