Several Pythons, a pip cache and a virtual environment per project
Windows installs Python in three different ways and each leaves its own folders. Where they are and what is safe to remove.
Python on Windows can be installed from python.org, from the Microsoft Store, through a distribution like Anaconda, or as part of another tool. Each puts things in a different place, and a machine that has done two of them has two of everything.
What is installed and where
py --list-paths
Get-ChildItem "$env:LOCALAPPDATA\Programs\Python","$env:LOCALAPPDATA\Microsoft\WindowsApps" -EA SilentlyContinue |
Select-Object Name
Get-ChildItem "$env:LOCALAPPDATA\pip\Cache" -EA SilentlyContinue |
ForEach-Object {
$s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue | Measure-Object Length -Sum).Sum
'{0,8:N0} MB pip cache' -f ($s/1MB)
}py --list-paths is the useful one: it lists every Python the launcher knows about, with its version and path. Anything there you cannot account for is a candidate.
The pip cache
pip cache dir
pip cache info
pip cache purgepip caches downloaded wheels under %LOCALAPPDATA%\pip\Cache, and it only grows. pip cache info reports its size and purge empties it. Everything in it is redownloadable, so the cost is bandwidth.
Virtual environments
Get-ChildItem $env:USERPROFILE -Recurse -Directory -Include .venv,venv,env -Force -EA SilentlyContinue |
Where-Object { Test-Path (Join-Path $_.FullName 'pyvenv.cfg') } |
ForEach-Object {
$s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue | Measure-Object Length -Sum).Sum
[PSCustomObject]@{ MB = [math]::Round($s/1MB); Path = $_.FullName }
} | Sort-Object MB -Descending | Select-Object -First 20The check for pyvenv.cfg is what distinguishes a real environment from a folder that happens to be called env. Each is a full copy of the packages that project needs, and one with a machine learning stack in it is several gigabytes on its own.
Recreating rather than keeping
An environment with a requirements.txt beside it is disposable: delete the folder, recreate it in a minute. Without one, the environment is the only record of what the project ran with, which is the reason to write the file before clearing anything.
The Store version and the launcher
The Microsoft Store Python installs into a protected packages folder and cannot be cleaned up by hand, only uninstalled. The python.exe stub in WindowsApps that opens the Store when Python is not installed is a placeholder, not an installation, and is worth knowing about because it confuses every first time setup.
Common questions
Where is the pip cache on Windows?
In %LOCALAPPDATA%\pip\Cache. Run pip cache info for its size and pip cache purge to empty it. Everything in it is downloadable again.
How do I find virtual environments on Windows?
Search for folders named .venv, venv or env that contain a pyvenv.cfg file, which is what distinguishes a real environment from a folder with a similar name.
How many Pythons do I have installed?
Run py --list-paths, which lists every interpreter the launcher knows about with its version and path. A machine that has installed from python.org and the Store has both.
Is it safe to delete a virtual environment?
Yes, if the project has a requirements file or lock file, because recreating it takes a minute. Without one, the environment is the only record of the versions the project worked with.