Deleting a Python virtual environment is the clean way to discard broken dependency state, remove an unused project sandbox, or reset a repository before rebuilding a known-good package set. Because the environment lives inside its own directory, removing it affects only that isolated interpreter tree rather than the system Python installation.
A venv environment contains its own interpreter, activation helpers, and private site-packages directory under a path such as .venv. Current Python documentation still treats these environments as disposable, so the normal recovery path is to save any needed package list, delete the environment directory, and create a fresh replacement instead of trying to repair stale files in place.
The steps below use a POSIX shell on Linux or macOS and assume the environment directory is named .venv inside the project root. Activation is only shell-local state and is not required to use the environment, so close terminals, editor tasks, or background jobs that still point at the environment before deleting it; on Windows the same deletion principle applies, but the activation and path syntax differ.
$ cd ~/workspace/service-api
Running the delete commands from the environment's parent directory keeps the removal target short and easy to verify.
$ ls .venv/bin/python .venv/pyvenv.cfg .venv/bin/python .venv/pyvenv.cfg $ ls -d .venv .venv
A venv directory normally contains its own interpreter path plus a pyvenv.cfg file. Stop here if the path points anywhere unexpected.
$ .venv/bin/python -m pip freeze > requirements.txt $ sed -n '1,5p' requirements.txt certifi==2026.2.25 charset-normalizer==3.4.6 idna==3.11 requests==2.33.0 urllib3==2.6.3
Calling the environment's interpreter directly captures packages from that environment even when the current shell is not activated against it.
$ printf '%s\n' "${VIRTUAL_ENV:-not active}"
/home/devops/workspace/service-api/.venv
If the variable prints the .venv path, deactivate the shell before deletion. If it prints not active, skip the next step.
(.venv) $ deactivate
Closing the shell also ends activation, but any editor, terminal tab, or background task still using the environment should be stopped separately.
$ rm -rf .venv
The rm -rf command deletes the target directory without prompting, so verify the parent directory and environment name before pressing Enter.
$ [ ! -d .venv ] && echo ".venv removed" .venv removed
A direct directory check confirms that the old interpreter tree and installed packages are no longer present.
$ python3 -m venv .venv
Reinstall application packages from the saved freeze file only after the replacement environment exists.