Introduction
This article will show how to setup a python virtual environment in Windows and in Linux machines.
Virtual Environments are crucial in keeping track of external packages that are used during production to determine which packages should be included under "requirements.txt".
It is good practice to set up a virtual environment for any python project development or application usage to maintain a constraint of including only packages that are needed for the current application or development and to avoid any installations that are challenging to trace.
Setup
Windows
- Install the python virtual environment package.
pip install virtualenv
- Create a virtual environment.
python -m venv <path to setup the environment>
- Activate the virtual environment.
<path to the environment>/Scripts/activate
Note: Libraries can be manually added under <path to the environment>/Lib/site-packages. Additionally, pip install operations will store the packages under the same directory.
Linux
- Install the python virtual environment package.
apt install python3-virtualenv
- Create a virtual environment.
python -m venv <path to setup the environment>
- Activate the virtual environment.
source <path to the environment>/bin/activate
Conclusion
This article has shown how to setup a python virtual environment in both Windows and Linux machines.
Comments
0 comments
Please sign in to leave a comment.