What is a virtual environment?
Virtual environments are useful tools in Python development that allow you to isolate package installations related to a specific project from the main system’s Python installation. This means you can have separate environments with different package dependencies for different projects.
Creating a virtual environment is easy using the venv
module in the Python standard library. The basic steps are as follows:
- Create the virtual environment by running the following command:
python3 -m venv venv
This will create a
venv
folder that contains the isolated environment. - Activate the virtual environment.
On Unix/Linux systems, run the following command:
source venv/bin/activate
On Windows, run the following command:
venv\Scripts\activate
Your command prompt will now show the virtual environment name enclosed in parentheses. Any package installations will now be isolated in this environment.
- You can install any packages needed for your project...