惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
U
Unit 42
WordPress大学
WordPress大学
Y
Y Combinator Blog
罗磊的独立博客
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
博客园 - 叶小钗
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
V
V2EX
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
酷 壳 – CoolShell
酷 壳 – CoolShell

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Don't Let Conda Eat Your Hard Drive: Python Environment C...
Sergey Nikif · 2026-04-29 · via DEV Community

My Anaconda installation was 28GB. I had 12 conda environments I'd forgotten about — one for every tutorial I'd followed, every Kaggle competition I'd started and abandoned, every "let me just try this library real quick" session. Each one had its own copy of NumPy, pandas, and scikit-learn. Three of them had PyTorch installed. That's 2-3GB per copy, sitting in folders I hadn't touched in months.

If you do any data science or ML work on a Mac, you've been there. Python's environment model is designed to keep things isolated — and it does, by duplicating everything. That isolation comes at a cost: disk space, and lots of it.

This guide covers every place Python stores things on macOS, how big each category typically gets, and how to clean them safely — whether you do it manually or let a tool handle it.

Quick Reference

Category Path Typical Size Safe to Delete?
Conda environments ~/anaconda3/envs/ or ~/miniconda3/envs/ 2-30 GB Yes (except active ones)
Conda pkgs cache ~/anaconda3/pkgs/ 2-10 GB Yes — conda clean --all
pip cache ~/Library/Caches/pip/ 0.5-5 GB Yes — pip cache purge
Virtual envs (.venv) Scattered across projects 1-15 GB total Yes (recreatable)
pyenv versions ~/.pyenv/versions/ 1-5 GB Yes (except active ones)
Poetry cache ~/Library/Caches/pypoetry/ 0.5-3 GB Yes — poetry cache clear --all
uv cache ~/.cache/uv/ 0.5-5 GB Yes — uv cache clean
pycache / .pyc Inside every project 10-500 MB total Yes — always safe
Tool caches .ruff_cache, .mypy_cache, .pytest_cache 10-200 MB total Yes — always safe
tox environments ~/.tox/ 0.5-5 GB Yes — regenerated on next run

Total potential savings: 10-50+ GB depending on how many projects and environments you've accumulated.


Why Python Environments Get So Large

Every virtual environment or conda environment is a self-contained copy of a Python interpreter plus all its packages. Nothing is shared between environments. Great for reproducibility. Terrible for disk space.

Here's why it adds up so fast:

  • PyTorch: 2-3 GB per installation
  • TensorFlow: 1-2 GB per installation
  • NumPy + SciPy + pandas + scikit-learn: ~500 MB as a stack
  • Jupyter + its dependencies: ~300 MB
  • Conda base environment: 3-5 GB before you install anything extra

Five conda environments with a ML framework plus the standard data science stack? That's 15-25 GB just in environments. Add caches, and you're at 20-40 GB of Python data on your machine.

The problem compounds because environments accumulate. You create one for a project, move on, forget about it. A year later, you have a dozen environments and no idea which ones matter.


1. Conda Environments

The biggest offender. Each conda environment is a full, isolated Python installation with its own packages. A single ML-focused environment can be 3-8 GB.

Where they live:

~/anaconda3/envs/
~/miniconda3/envs/
~/opt/anaconda3/envs/
~/miniforge3/envs/
~/mambaforge/envs/

Enter fullscreen mode Exit fullscreen mode

The exact path depends on which distribution you installed and how you installed it. If you're not sure, check:

conda env list

Enter fullscreen mode Exit fullscreen mode

This shows every environment and its path. You'll probably be surprised by how many there are.

How to clean them:

First, identify which environments you actually use. Anything you haven't touched in 3+ months is probably safe to remove.

Remove a specific environment:

conda env remove -n old-project-env

Enter fullscreen mode Exit fullscreen mode

Remove multiple environments:

conda env remove -n kaggle-titanic
conda env remove -n nlp-tutorial
conda env remove -n test-env-2024

Enter fullscreen mode Exit fullscreen mode

What to keep: Don't remove base — it's your main conda installation. Keep any environment that belongs to an active project, especially if it has a complex dependency setup that took time to get working.

How big are they? Check individual environment sizes:

du -sh ~/anaconda3/envs/* 2>/dev/null
du -sh ~/miniconda3/envs/* 2>/dev/null

Enter fullscreen mode Exit fullscreen mode


2. Conda Package Cache

Even after deleting environments, conda keeps a cache of every package it has ever downloaded. This cache lives inside your conda installation directory.

Where it lives:

~/anaconda3/pkgs/
~/miniconda3/pkgs/

Enter fullscreen mode Exit fullscreen mode

How to clean it:

conda clean --all

Enter fullscreen mode Exit fullscreen mode

This removes:

  • Cached package tarballs
  • Extracted packages no longer linked to any environment
  • Index cache

It's completely safe. Conda will re-download any package it needs next time you create an environment or install something.

Typical savings: 2-10 GB, depending on how long you've been using conda.


3. pip Cache

Every time you pip install something, pip downloads the wheel or sdist and caches it locally. This speeds up future installs, but the cache grows indefinitely.

Where it lives on macOS:

~/Library/Caches/pip/

Enter fullscreen mode Exit fullscreen mode

(On Linux it's ~/.cache/pip/ — if you see that path in tutorials, the macOS equivalent is the Library path above.)

How to clean it:

pip cache purge

Enter fullscreen mode Exit fullscreen mode

Or manually:

rm -rf ~/Library/Caches/pip

Enter fullscreen mode Exit fullscreen mode

Typical savings: 0.5-5 GB. If you install a lot of packages with native extensions (like numpy, scipy, torch), the cache tends to be larger because those wheels are big.

Is it safe? Completely. The cache only speeds up reinstallation — pip will re-download anything it needs.


4. Virtual Environments (.venv, venv, env)

Unlike conda environments, which live in a central location, Python virtual environments are typically created inside project directories. This makes them easy to forget about — they're scattered across your filesystem.

Common locations:

~/projects/my-app/.venv/
~/projects/my-app/venv/
~/projects/my-app/env/

Enter fullscreen mode Exit fullscreen mode

The standard naming conventions are .venv, venv, and env. A valid virtual environment contains a pyvenv.cfg file and a bin/python executable.

Finding all of them:

find ~ -name "pyvenv.cfg" -maxdepth 5 2>/dev/null

Enter fullscreen mode Exit fullscreen mode

This finds every virtual environment within 5 levels of your home directory. Each result shows the root of a venv — the parent directory is what you'd delete.

A more targeted approach:

find ~/projects ~/code ~/dev -type d \( -name ".venv" -o -name "venv" -o -name "env" \) -maxdepth 4 2>/dev/null

Enter fullscreen mode Exit fullscreen mode

How to clean them:

Simply delete the directory:

rm -rf ~/projects/old-project/.venv

Enter fullscreen mode Exit fullscreen mode

Is it safe? Yes — as long as you can recreate it. If the project has a requirements.txt, pyproject.toml, or Pipfile, you can always rebuild:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Enter fullscreen mode Exit fullscreen mode

Orphaned environments are especially safe to delete — these are venvs where the parent project no longer has any Python source files or config files. The project was probably deleted or moved, but the environment was left behind.

Typical total size: 1-15 GB across all projects, depending on how many you have and whether any include ML frameworks.


5. pyenv, Poetry, and uv

A few more Python tools that accumulate disk usage:

pyenv installs each Python version separately at ~/.pyenv/versions/. Each version is 200-500 MB. Run pyenv versions to see what's installed, and pyenv uninstall 3.9.7 to remove old point releases.

Poetry caches packages at ~/Library/Caches/pypoetry/. Clean with poetry cache clear --all .

uv caches aggressively at ~/.cache/uv/ for speed — expect 1-5 GB if you use it regularly. Clean with uv cache clean.


6. pycache and Tool Caches

These are small individually but add up across many projects.

pycache directories contain compiled Python bytecode (.pyc files). Every Python project has them scattered throughout its source tree. Tool caches include .ruff_cache/, .mypy_cache/, .pytest_cache/, and .tox/ (tox environments at ~/.tox/ can be large).

All of these are completely safe to delete — they regenerate automatically.

find ~/projects -type d -name "__pycache__" 2>/dev/null | head -20
find ~/projects -type d \( -name ".mypy_cache" -o -name ".ruff_cache" -o -name ".pytest_cache" \) 2>/dev/null

Enter fullscreen mode Exit fullscreen mode

Typical total size: 10-500 MB across all projects. Not huge, but it's free space with zero risk.


What's Safe to Delete vs. What to Keep

Here's the short version:

Always safe (zero risk):

  • pip cache
  • conda package cache (conda clean --all)
  • __pycache__ / .pyc files everywhere
  • .ruff_cache, .mypy_cache, .pytest_cache
  • uv and Poetry caches

Safe if you can recreate (low risk):

  • Virtual environments with a requirements.txt or pyproject.toml nearby
  • Conda environments you haven't used in months
  • Old pyenv versions

Verify first:

  • Conda environments for active projects with complex dependency pinning
  • Virtual environments with no dependency file (you might not remember what was installed)
  • The conda base environment — don't delete this unless you're uninstalling conda entirely

Prevention: Keeping Python Lean

You can't avoid the problem entirely, but you can slow the growth:

Use Miniconda instead of Anaconda. A full Anaconda install is 3-5 GB out of the box because it includes hundreds of packages. Miniconda starts at ~400 MB. If you're already on Anaconda, switching is probably the single biggest disk savings you can make.

Use Miniforge or Mambaforge on Apple Silicon. Miniforge gives you conda-forge as the default channel with native ARM packages. Mamba (a faster conda replacement) is included with Mambaforge.

Clean caches monthly. Run conda clean --all and pip cache purge once a month. It takes 5 seconds and prevents multi-gigabyte cache buildup.

Export before deleting. The environment file is what matters, not the installed copy.

conda env export -n my-env > environment.yml
conda env remove -n my-env

Enter fullscreen mode Exit fullscreen mode


The Automated Way

Finding all Python environments manually — across conda directories, scattered venvs, multiple cache locations — is tedious. That's part of why the cleanup doesn't happen: it's not hard, it's just annoying enough that you put it off.

This is exactly the problem I built MegaCleaner to solve.

MegaCleaner's Python scanner finds everything covered in this article automatically:

  • Conda environments across all installation paths (~/anaconda3/envs/, ~/miniconda3/envs/, ~/opt/anaconda3/envs/, ~/miniforge3/envs/, ~/mambaforge/envs/)
  • Virtual environments (.venv, venv, env) scattered across all your project directories, with orphan detection — it flags venvs where the parent project no longer has source files
  • pip cache at ~/Library/Caches/pip/
  • uv cache at ~/.cache/uv/
  • Poetry cache at ~/Library/Caches/pypoetry/
  • tox environments at ~/.tox/
  • __pycache__ directories and .pyc files across all projects
  • Tool caches.ruff_cache, .mypy_cache, .pytest_cache in every project

Each item gets a confidence level: caches are marked "definitely safe," stale environments are "probably safe," and active environments are "verify first." Everything goes to Trash (undoable) — nothing is permanently deleted.

And Python is just one of 29 scanners (21 developer tools + 8 system categories). If you also use Docker, Node.js, Xcode, Rust, or Homebrew, those get scanned too.

How it works:

  • Scan is free — see exactly how much space Python (and everything else) is using
  • Confidence levels — every item is labeled so you know what's safe
  • One click — select what to clean, hit Clean, done
  • $49 one-time — not a subscription

Quick Reference Commands

Bookmark this section for next time your disk fills up.

conda env list                                    # List all environments
du -sh ~/anaconda3/envs/* 2>/dev/null             # Check environment sizes
conda env remove -n <env-name>                    # Remove an environment
conda clean --all                                 # Clean package cache

# pip
pip cache info                                    # Check cache size
pip cache purge                                   # Purge cache

# Virtual environments
find ~ -name "pyvenv.cfg" -maxdepth 5 2>/dev/null # Find all venvs
rm -rf /path/to/project/.venv                     # Remove a venv

# pyenv
pyenv versions                                    # List installed versions
pyenv uninstall <version>                         # Remove a version

# Other caches
uv cache clean                                    # Clean uv cache
poetry cache clear --all .                        # Clean Poetry cache

# __pycache__ cleanup
find ~/projects -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null

Enter fullscreen mode Exit fullscreen mode


Summary

Python environments silently consume 10-50 GB on most data scientists' and ML engineers' Macs. The biggest culprits are forgotten conda environments (2-8 GB each) and duplicated ML framework installations across virtual environments.

At a minimum, do this quarterly:

  1. Run conda env list and delete environments you don't recognize
  2. Run conda clean --all to clear the package cache
  3. Run pip cache purge to clear the pip download cache
  4. Search for orphaned .venv directories in old project folders
  5. Check ~/.pyenv/versions/ for Python versions you no longer use

The manual cleanup takes 10-15 minutes if you follow this guide. Or scan with MegaCleaner and do it in under a minute.

Either way, your hard drive will thank you.