Last Updated : 14 May, 2025
A virtual environment is like a separate workspace for your Python projects. It’s a self-contained folder that has its own Python installation and any libraries or packages your project needs, completely isolated from other projects. Its key benefits include:
Think of a virtual environment as a safety bubble for each of your Python projects. Let’s say you're working on two different projects:
If you install everything globally on your main system , one project might break the other due to version mismatches. That's where virtual environments come in. They allow you to:
To manage dependencies and isolate project environments, it’s best practice to create a virtual environment. You can easily set one up using the steps below.
Step 1: Use pip to install the virtualenv package:
pip3 install virtualenvInstalling virtualenv
Now check your installation
virtualenv --version
Step 2: Create a virtual environment. After running the below command, a directory named virtualenv_name will be created. This is the directory that contains all the necessary executables to use the packages that a Python project would need.
virtualenv virtualenv_name
Step 3: Create a new virtual environment
virtualenv -p /usr/bin/python3 venv
where venv is the name of the virtual environment you can change it accordingly
Create new venvStep 4: Activate our newly created virtual environment
source venv/bin/activateactivated venv
If everything works well then the name of your virtual environment will appear on the left side of the terminal as shown in the above image which means that the virtual environment is currently active.
How to Deactivate or Exit the Virtual EnvironmentOnce you're done working in the virtual environment, it’s good practice to deactivate it to avoid unintentional use by simply executing the below command.
Deactivated venvdeactivate
As you can see in the above image the name of our virtual environment disappeared.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4