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