What is a .venv or venv folder, and is it safe to delete?

A .venv or venv folder is a project's private Python environment with its own interpreter link and installed packages, and it can be deleted and rebuilt if you know what was installed.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

A .venv or venv folder is one Python project's private environment, with its own installed packages. Look first. It is safe to delete if the project lists its dependencies in requirements.txt or a lockfile, because you can recreate it. If you installed packages by hand, note them before deleting.

Path
.venv or venv folders inside Python projects
What it is
A project's isolated Python environment created with python -m venv
Typical size
Tens to hundreds of megabytes; gigabytes with machine-learning packages
Made by
Python (venv, virtualenv) with pip, often via uv or an editor
Safe to delete?
Look first
Comes back?
Yes if the project has a requirements.txt or lockfile; otherwise you must recall what you installed

What is in this folder?

Python's venv module creates the folder and puts a pyvenv.cfg file inside, which is how tools recognize it. It contains links to the Python interpreter and a lib/site-packages folder with everything you pip installed.

Like node_modules, each project keeps its own copy, so a Mac with many projects accumulates many of them, especially when project folders are copied.

Is it safe to delete?

Usually. A virtual environment is meant to be disposable. If the project has a requirements.txt, pyproject.toml or lockfile, you can rebuild it in a minute or two. It is Look first rather than Safe to clear because packages installed ad hoc may not be recorded, and some environments pin an older Python that is hard to get back.

Run pip freeze inside the environment first if you are not sure.

How do I clear it by hand?

  1. Stop anything running from the environment, and deactivate it.
  2. Optionally save the package list.
  3. Delete the folder, and recreate it when you return to the project.
deactivate
.venv/bin/pip freeze > requirements.txt
rm -rf .venv
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
Run the first two commands from the project folder. The last two rebuild the environment, so skip them if you are done with the project.

How do I stop it growing?

Delete the environments of finished projects, and share one environment across small scripts.

How Clean House handles it

Clean House identifies a folder as a Python virtual environment only when it has a pyvenv.cfg, so ordinary folders named venv are not touched. An environment inside a project is shown with that project, and a standalone one gets its own row, named after the folder that holds it. Files go to the Trash.

Questions

Is it safe to delete a .venv folder?

Yes if you can reinstall the packages from requirements.txt or a lockfile. Save pip freeze first if unsure.

Will deleting .venv delete my code?

No. Your source code sits outside the environment folder.

Why are there so many venv folders on my Mac?

Each project creates its own, and copying project folders copies the environment too.

Sources

  1. Python Docs: venv, creation of virtual environments
  2. pip Docs: pip freeze