Python venv Cheat Sheet/Recreate an existing environment in place

Clear an environment directory before recreating it.

Section: Create environments

Recreate an existing environment in place

bash
bash
python -m venv --clear .venv
Explanation

Useful when the directory exists and you want a fresh environment in the same path.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Create environments
Create a .venv environment
Create a conventional project-local virtual environment.
OpenIn sheetbashsame section
Create with python3
Use python3 explicitly on systems where python points elsewhere.
OpenIn sheetbashsame section
Create with Windows py launcher
Create an environment using the Windows Python launcher.
OpenIn sheetpowershellsame section
Create with a specific Python version
Use a specific interpreter to choose the base Python version.
OpenIn sheetbashsame section
Create in a custom directory
Create a venv anywhere, not just in the project root.
OpenIn sheetbashsame section
Create without pip
Skip pip bootstrap during environment creation.
OpenIn sheetbashsame section