Virtual Environments
Setup¶
Sometimes you want to keep libraries from polluting system installs or use a different version of libraries than the ones installed on the system. You might also not have permissions to install libraries system-wide. For this purpose, the standard library as of Python 3.3 comes with a concept called “Virtual Environment”s to help maintain these separate versions.
A more in-depth tutorial is found on Virtual Environments and Packages.
However, for the quick and dirty:
Go to your project’s working directory:
Activate the virtual environment:
On Windows you activate it with:
Use pip like usual:
Congratulations. You now have a virtual environment all set up.
Additional info¶
It can be useful to set up a requirements.txt, so you can just put all of your dependencies in there and have pip install it. For instance, if you wanted to have the latest 2.0 version of pycord and pytz, just create a file named requirements.txt with the following contents:
And then (in your virtual environment) you can just execute
To keep from committing your virtual environment to git, you can set up a .gitignore file with the following line (assuming you named your virtual environment venv like the above example):