Python virtual environments allows you load all of the dependencies a project may have into its own isolated environment. This means that if you have multiple projects with different versions of dependencies or wish to move your environment to a different location for example production. You will only need to move the dependencies required.
To setup a virtual environment perform the following steps:
- Ensure the Virtual Environments module is installed.
pip install virtualenv - To create a new virtual environment run the following command
python -m venv C:\Scripts\project_Name\venv - To activate the virtual environment navigate into the venv/Scripts folder created by the step above and execute activate
activate - To deactivate the environment simply type deactivate
deactivate
- To export a list of requirements from your environment
pip freeze --local > requirements.txt - To install the exported requirements file
pip install -r requirements.txt
Leave a Reply