A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/how-to-leave-exit-deactivate-a-python-virtualenv/ below:

How to leave/exit/deactivate a Python virtualenv

How to leave/exit/deactivate a Python virtualenv

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:

Why use a virtual environment?

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:

How to create a Python Virtual environment?

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 virtualenv
Installing 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 venv

Step 4: Activate our newly created virtual environment

source venv/bin/activate
activated 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 Environment

Once 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.

deactivate

Deactivated venv

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