This article will teach you how to use Python to create and manage a virtual environment.
A virtual setup is an isolated workstation that allows you to manage Python packages independently for each project, eliminating conflicts.
Let us follow the steps:
- Make sure Python is installed by opening your terminal and checking the version with:
python --version
or
python3 --version
- Run the following to create a virtual environment in your project folder:
python -m venv env
This creates an isolated environment named env.
- Activate the virtual environment:
- On Windows, run:
.\env\Scripts\activate
- On macOS/Linux, run:
source env/bin/activate
Your terminal prompt will change to show it’s active.
- On Windows, run:
- Install packages inside the activated setting using ‘pip’, for instance:
pip install requests
- When finished, deactivate the virtual environment by running:
deactivate
In such a manner, you can create and use a virtual environment in Python. If you require further assistance, please don’t hesitate to contact our support staff.
Want to explore alternative installation methods? Learn How to Install Python libraries without using the pip command