Python
Virtualenv
Programming
Coding
Environment Setup

How to delete a Python virtualenv (venv, conda, Poetry, pipenv)

Codemia Knowledge Hub ·

To delete a Python virtual environment, deactivate it if it is active and then remove its directory. A virtual environment is just a folder, so there is no uninstall command, registry entry or daemon to stop.

bash
deactivate          # if currently active
rm -rf .venv        # remove the environment directory

Environments managed by virtualenvwrapper, conda, Poetry, pipenv or pyenv-virtualenv have their own removal commands, and you may also need to update IDE and CI references afterwards.

What is inside a virtual environment

ContentsPurpose
bin/ (or Scripts/ on Windows)Python executable, pip, activate script
lib/pythonX.Y/site-packages/All installed packages
pyvenv.cfgConfiguration file pointing to the base Python
include/Header files for C extensions

Nothing lives outside this directory: no database, system service or package manager metadata. Delete the directory and the environment is gone.

Step 1: check which environment is active

Make sure you are about to remove the right one:

bash
1# Show which Python is currently in use
2which python
3
4# Show the environment path
5echo $VIRTUAL_ENV
6
7# Check the Python version
8python --version

On Windows PowerShell:

powershell
Get-Command python
$env:VIRTUAL_ENV
python --version

If $VIRTUAL_ENV points to the environment you want to delete, deactivate it first.

Step 2: deactivate it

bash
deactivate

deactivate is a shell function added by the activate script. If it is not found, you are either not in an environment or using a tool (like Poetry or pipenv) that manages activation differently.

Deactivating matters. If you delete an active environment, PATH still points to its deleted bin/ directory, so python, pip and other commands fail with "command not found" until you open a new terminal. Afterwards, check that python points to your system or global interpreter:

bash
which python
# Should NOT point to the deleted environment path

If the environment works, capture its packages so you can recreate it:

bash
pip freeze > requirements.lock.txt

pip list --format=freeze produces the same format:

bash
pip list --format=freeze > requirements.lock.txt

If you use pyproject.toml or poetry.lock, your dependencies are already tracked. For a plain venv without a lock file, this takes seconds and saves you from forgetting which version of a package you were using.

Step 4: delete the directory

Linux / macOS

bash
rm -rf .venv

Windows Command Prompt

cmd
rmdir /s /q .venv

Windows PowerShell

powershell
Remove-Item .venv -Recurse -Force

Replace .venv with your environment's actual name or path (e.g., env, myproject-env, ~/.virtualenvs/myenv). Check the path with ls or echo before running rm -rf: running it in the wrong directory is the most dangerous mistake, and a typo like rm -rf .v env (note the space) deletes .v and a separate directory named env.

Verify deletion

bash
ls -la | grep venv    # should show nothing
which python          # should point to system Python

Removing environments created by other tools

When a tool created the environment, use its own removal command instead of rm, because it also cleans up the tool's metadata.

virtualenvwrapper

bash
rmvirtualenv myenv

This removes the environment from $WORKON_HOME (typically ~/.virtualenvs/) and updates wrapper state. Delete from $WORKON_HOME by hand only if rmvirtualenv is unavailable.

conda

bash
conda deactivate
conda env remove -n myenv

Verify removal:

bash
conda env list

Do not delete conda environments by removing the folder. Conda keeps an internal registry, and the folder approach leaves orphaned entries in it.

Poetry

Poetry keeps environments in a central cache directory:

bash
1# List environments for the current project
2poetry env list
3
4# Remove a specific environment
5poetry env remove python3.11
6
7# Remove all environments for the project
8poetry env remove --all

pipenv

bash
pipenv --rm

This removes the virtualenv tied to the current project directory.

pyenv-virtualenv

bash
pyenv virtualenv-delete myenv

Create and remove commands by tool

ToolCreate CommandRemove CommandEnvironment Location
venv (stdlib)python -m venv .venvrm -rf .venvProject directory
virtualenvvirtualenv .venvrm -rf .venvProject directory
virtualenvwrappermkvirtualenv myenvrmvirtualenv myenv$WORKON_HOME
condaconda create -n myenvconda env remove -n myenvConda envs directory
Poetrypoetry installpoetry env remove python3.11Centralized cache
pipenvpipenv installpipenv --rmCentralized cache
pyenv-virtualenvpyenv virtualenv 3.11 myenvpyenv virtualenv-delete myenv~/.pyenv/versions/

Fixing references to the deleted environment

Other tools may still point at the old path, which shows up as confusing "Python not found" errors.

IDE interpreter settings

In VS Code, check .vscode/settings.json:

json
{
  "python.defaultInterpreterPath": ".venv/bin/python"
}

Point it at the new environment, or remove it so VS Code auto-detects one. In PyCharm, go to Settings > Project > Python Interpreter and remove the stale entry.

CI/CD configuration

Update pipeline files that reference the environment path:

yaml
1# Before
2- run: source .venv/bin/activate && pytest
3
4# After (if environment name changed)
5- run: source .env/bin/activate && pytest

Shell configuration

Check ~/.bashrc, ~/.zshrc or ~/.profile for aliases or PATH entries that reference the deleted environment.

Recreating the environment

bash
1python -m venv .venv
2source .venv/bin/activate       # Linux/macOS
3# .\.venv\Scripts\Activate.ps1  # Windows PowerShell
4pip install --upgrade pip
5pip install -r requirements.txt

For conda:

bash
conda create -n myenv python=3.11
conda activate myenv
conda install --file requirements.txt

On team projects, script this so every developer can go from nothing to a working environment with one command, and pick one environment tool per project. If half the team uses venv and half uses conda, the .gitignore, setup instructions and CI config all have to handle both.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms