If you're a Python developer on macOS, you might not realize how much disk space Python-related files consume. Between pip's download cache, conda environments, multiple pyenv versions, scattered virtualenvs, and __pycache__ directories, it's common to find 10-50GB+ of Python debris across your system.
This guide covers every Python-related cache and environment on macOS, with exact commands to audit and clean each one.
Before cleaning anything, let's see what's consuming disk space. Run this audit to get the full picture:
echo "=== pip cache ===" pip cache info 2>/dev/null || pip3 cache info 2>/dev/null echo -e "\n=== pip cache directory ===" du -sh ~/Library/Caches/pip/ 2>/dev/null echo -e "\n=== conda environments ===" du -sh ~/miniconda3/ 2>/dev/null du -sh ~/anaconda3/ 2>/dev/null du -sh ~/opt/anaconda3/ 2>/dev/null echo -e "\n=== pyenv versions ===" du -sh ~/.pyenv/versions/*/ 2>/dev/null echo -e "\n=== Poetry cache ===" du -sh ~/Library/Caches/pypoetry/ 2>/dev/null echo -e "\n=== Jupyter ===" du -sh ~/Library/Jupyter/ 2>/dev/null echo -e "\n=== virtualenvs (home) ===" du -sh ~/.virtualenvs/ 2>/dev/null du -sh ~/.local/share/virtualenvs/ 2>/dev/null
You'll likely find several gigabytes spread across these locations. Here's what typically consumes the most:
| Location | Typical Size | Safe to Clean? |
|---|---|---|
| pip cache | 2-15 GB | Yes -- fully safe |
| Conda environments | 5-40 GB | Unused envs: yes |
| pyenv versions | 1-10 GB | Old versions: yes |
| virtualenvs / .venv | 1-20 GB | Recreatable: yes |
| __pycache__ | 100 MB - 2 GB | Yes -- fully safe |
| Poetry cache | 1-8 GB | Yes -- fully safe |
| Jupyter data | 100 MB - 2 GB | Kernels: be careful |
Every time you run pip install, pip downloads and caches wheel files. Over months and years, this cache grows silently.
pip cache info # Typical output: # Package index page cache location: ... # Package index page cache size: 42.2 MB # Number of HTTP files: 847 # Wheels location: /Users/you/Library/Caches/pip/wheels # Wheels size: 4.7 GB # Number of wheels: 1284
# Remove ALL cached packages pip cache purge # Or remove cache for a specific package pip cache remove numpy # Verify it's clean pip cache info
# pip cache lives here on macOS du -sh ~/Library/Caches/pip/ # Nuclear option -- delete everything rm -rf ~/Library/Caches/pip/ # pip will recreate the directory automatically
Conda is one of the biggest disk space consumers for Python developers. A base Anaconda install is 3-5GB, and each environment can add 1-5GB more. Data science libraries like PyTorch, TensorFlow, and CUDA toolkits are especially large.
# List all environments with sizes
conda env list
du -sh $(conda info --envs | grep -v "^#" | awk '{print $NF}' | grep -v "^$")
# Check conda package cache
du -sh $(conda info --base)/pkgs/
# Check total conda installation
du -sh ~/miniconda3/ # or ~/anaconda3/
# Remove index cache, lock files, unused tarballs, and packages conda clean --all # More targeted options: conda clean --tarballs # remove downloaded .tar.bz2 files conda clean --packages # remove unused packages from writable pkgs dirs conda clean --index-cache # remove cached channel index files conda clean --logfiles # remove log files
conda clean --all: 2-10GB. This only removes cached/unused files, not your installed environments.
# List all environments
conda env list
# Remove an environment you no longer need
conda env remove --name old_project
# See how much space a specific env uses
du -sh $(conda info --envs | grep old_project | awk '{print $NF}')
Full Anaconda installs 250+ packages you probably don't need. Switching to Miniconda saves 3-4GB immediately:
# Export your environments first! conda env export --name myenv > myenv.yml # Install Miniconda (much smaller) brew install --cask miniconda # Recreate only what you need conda env create -f myenv.yml
Each Python version installed through pyenv takes 50-200MB. If you've installed many versions over time, this adds up.
# List installed versions with sizes
for v in $(pyenv versions --bare); do
size=$(du -sh "$(pyenv prefix $v)" 2>/dev/null | cut -f1)
echo "$size Python $v"
done
# Which version are you actually using?
pyenv version
# Uninstall versions you don't need
pyenv uninstall 3.8.12
pyenv uninstall 3.9.7
# After cleanup, rehash
pyenv rehash
.python-version files before removing versions.
Virtual environments are the biggest hidden disk hog for Python developers. Every project with a .venv or venv folder contains a complete copy of Python and all installed packages.
# Find .venv and venv directories in common project locations
find ~/Projects ~/Developer ~/Code ~/Documents -maxdepth 4 \
-type d \( -name ".venv" -o -name "venv" -o -name ".virtualenv" \) \
-exec du -sh {} \; 2>/dev/null | sort -rh
# Check centralised virtualenvs
du -sh ~/.virtualenvs/*/ 2>/dev/null
du -sh ~/.local/share/virtualenvs/*/ 2>/dev/null
# Total across all locations
find ~ -maxdepth 5 -type d -name ".venv" -exec du -sm {} \; 2>/dev/null | \
awk '{total += $1} END {print total " MB total across all .venv dirs"}'
# Remove venv from a project you're not working on # (You can always recreate with: python -m venv .venv && pip install -r requirements.txt) rm -rf ~/Projects/old_project/.venv # Remove all pipenv virtualenvs rm -rf ~/.local/share/virtualenvs/* # Remove all virtualenvwrapper envs rm -rf ~/.virtualenvs/*
requirements.txt or pyproject.toml. If a project has its dependencies pinned, you can safely delete and recreate the venv anytime.
Python creates __pycache__ directories and .pyc bytecode files automatically. While individually small, they accumulate across hundreds of packages and projects.
# Find and count all __pycache__ directories
find ~/Projects -type d -name "__pycache__" | wc -l
# See total size
find ~/Projects -type d -name "__pycache__" -exec du -sm {} + 2>/dev/null | \
awk '{total += $1} END {print total " MB"}'
# Delete all __pycache__ in your projects
find ~/Projects -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null
# Delete .pyc files too
find ~/Projects -name "*.pyc" -delete
find ~/Projects -name "*.pyo" -delete
PYTHONDONTWRITEBYTECODE=1 in your shell profile. Add export PYTHONDONTWRITEBYTECODE=1 to ~/.zshrc.
Poetry maintains its own package cache and virtual environments. The cache can grow to several GB, especially with large data science dependencies.
# Check Poetry cache size du -sh ~/Library/Caches/pypoetry/ # List Poetry's cache details poetry cache list # Clear all caches poetry cache clear --all . # Or clear a specific cache poetry cache clear pypi --all # Poetry virtualenvs (separate from cache) poetry env list du -sh $(poetry config virtualenvs.path)/*/ 2>/dev/null # Remove specific Poetry virtualenv poetry env remove python3.11
Jupyter stores kernels, runtime files, and data that accumulates over time.
# Check Jupyter data directory du -sh ~/Library/Jupyter/ # List installed kernels jupyter kernelspec list # Remove unused kernels jupyter kernelspec uninstall old_kernel_name # Clean runtime files rm -rf ~/Library/Jupyter/runtime/* # IPython history and cache du -sh ~/.ipython/ rm -rf ~/.ipython/profile_default/db/ rm -rf ~/.ipython/profile_default/history.sqlite
It's common to have 3-5 different Python installations on macOS without realizing it. Each one wastes space.
# Find ALL Python installations which -a python python3 # Check common locations ls -la /usr/bin/python* # Apple's system Python ls -la /usr/local/bin/python* # Homebrew / manual installs ls -la /opt/homebrew/bin/python* # Homebrew (Apple Silicon) ls -la /Library/Frameworks/Python.framework/Versions/ # Size of Homebrew Python du -sh $(brew --prefix python@3.11)/ 2>/dev/null du -sh $(brew --prefix python@3.12)/ 2>/dev/null du -sh $(brew --prefix python@3.13)/ 2>/dev/null # Size of Python.org framework installs du -sh /Library/Frameworks/Python.framework/ 2>/dev/null
# If using pyenv, you don't need Homebrew Python brew uninstall python@3.11 # If not needed by other formulae # Remove Python.org framework installs # (Check /Applications/ for Python folders first) sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.9/ sudo rm -rf /Applications/Python\ 3.9/ # Verify your working Python python3 --version which python3
/usr/bin/python3. Some macOS services depend on it. Only clean up duplicates from Homebrew, pyenv, or Python.org installers.
Add this to your ~/.zshrc:
# Python cleanup alias
alias pyclean='echo "Cleaning pip cache..." && \
pip cache purge 2>/dev/null; \
echo "Cleaning conda caches..." && \
conda clean --all -y 2>/dev/null; \
echo "Cleaning __pycache__..." && \
find ~/Projects -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null; \
find ~/Projects -name "*.pyc" -delete 2>/dev/null; \
echo "Cleaning Poetry cache..." && \
poetry cache clear --all . 2>/dev/null; \
echo "Python cleanup complete!"'
# Open crontab
crontab -e
# Add weekly pip cache cleanup (every Sunday at 3am)
0 3 * * 0 pip cache purge 2>/dev/null
0 3 * * 0 conda clean --all -y 2>/dev/null
0 3 * * 0 find ~/Projects -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null
If you prefer a visual approach, ClearDisk is a free, open-source macOS menu bar app that detects and cleans pip cache, conda environments, virtualenvs, __pycache__, and 12+ other developer caches with one click.
# Install with Homebrew brew tap bysiber/cleardisk && brew install --cask cleardisk
ClearDisk scans all standard Python cache locations automatically and shows you exactly how much space each one uses before you clean.
| Task | Command |
|---|---|
| Clear pip cache | pip cache purge |
| pip cache size | pip cache info |
| Conda full cleanup | conda clean --all |
| Remove conda env | conda env remove --name OLD_ENV |
| List pyenv versions | pyenv versions |
| Remove pyenv version | pyenv uninstall 3.x.x |
| Find all .venv dirs | find ~ -maxdepth 5 -type d -name ".venv" |
| Delete __pycache__ | find . -type d -name "__pycache__" -exec rm -rf {} + |
| Clear Poetry cache | poetry cache clear --all . |
| Check Jupyter data | du -sh ~/Library/Jupyter/ |
| All Pythons on system | which -a python python3 |
| GUI cleanup (all caches) | brew tap bysiber/cleardisk && brew install --cask cleardisk |