Can I delete __pycache__? Yes, it's safe on every Mac
**/__pycache__Yes. __pycache__ is Python's bytecode cache, and deleting it is completely safe. Python rebuilds it automatically and instantly the next time your code runs, so the worst case is a slightly slower first import. If a search on your Mac turned up dozens of these folders, you can clear every one of them without breaking anything.
What it is
When Python imports a module, it compiles the .py source file into bytecode and saves the result as a .pyc file inside a __pycache__ folder sitting next to the source. The filenames look like utils.cpython-312.pyc, where the middle part records which Python version compiled it. The whole point is speed: on the next import, Python loads the precompiled bytecode instead of parsing the source again. It is a convenience cache, nothing more. Your actual code lives in the .py files, and those are never touched.
The reason __pycache__ shows up everywhere is that Python creates one in every folder it imports from. A single project can hold dozens, and a virtual environment's site-packages can hold hundreds, one per installed package directory. Each folder is usually small, often just kilobytes to a few megabytes, but on a Mac with years of Python projects the combined total can quietly reach hundreds of megabytes. If you use several Python versions, the folders grow further because each version writes its own set of .pyc files.
Is it safe to delete?
Deleting __pycache__ costs you nothing permanent. There is no setting, no data, and no code inside it, only compiled copies of files you still have. The moment you run or import the code again, Python recompiles the modules it needs and writes a fresh __pycache__ on the spot. The penalty is a fraction of a second of extra startup time on that first run, and only for the modules actually imported.
Two small warnings. First, delete the __pycache__ folders themselves, not the project folders that contain them; the .py files next to them are your real work. Second, if you are clearing space inside a virtual environment, remove only the __pycache__ folders and leave the rest of the environment intact, since the environment itself takes real work to rebuild.
How to check its size
In Finder: There is no single __pycache__ path; one lives beside almost every Python file you have run. Open Finder, choose Go > Go to Folder, and enter the project you want to inspect, for example ~/Projects/my-app. Press Command-F, click your project's name in the search scope bar so you search that folder rather than This Mac, and type __pycache__. Select any result and press Command-I to see its size.
In Terminal:
du -sh ~/Projects/my-app/__pycache__Replace ~/Projects/my-app with your real project path; ~ expands to /Users/yourname. If the path contains spaces, put quotes around that part, like du -sh ~/Projects/"My App"/__pycache__. To list every __pycache__ under your home folder with sizes, run find ~ -type d -name __pycache__ -prune -exec du -sh {} + 2>/dev/null; the last part hides permission warnings from folders macOS protects.
How to clean it
- In Finder, open the project folder you want to clean.
- Press Command-F, then click the folder's name in the scope bar (next to This Mac) so the search stays inside that project.
- Type __pycache__ in the search field, and when the suggestion menu appears, click Name matches: __pycache__ so the results are only folders with that exact name.
- Select the resulting folders (Command-A grabs them all) and press Command-Delete to move them to the Trash.
- Repeat for other projects, then empty the Trash when you are ready to reclaim the space.
Python has no built-in cleanup command for these folders. Diskmack identifies every __pycache__ across your projects automatically and cleans them the safe way.
Will it come back?
Yes, immediately, and that is by design. Python writes a new __pycache__ the instant you run or import the code again, so a cleared folder can reappear within seconds. That is not a sign anything went wrong; it means the cache is doing its job. Treat deleting __pycache__ as an occasional tidy-up rather than a permanent fix, and expect the space to creep back as you keep working in Python. The folders you clear in abandoned projects, though, stay gone.
Common questions
Why does __pycache__ keep coming back after I delete it?
Because Python recreates it automatically whenever a module is imported. Deleting it is harmless but temporary. If a project is retired and you never run it again, its __pycache__ folders stay deleted.
Can I stop Python from creating __pycache__ at all?
Yes. Run scripts with python -B, or set the environment variable PYTHONDONTWRITEBYTECODE=1, and Python skips writing .pyc files. The trade-off is slightly slower imports, since Python has to recompile the source each run. If you just want the folders out of your projects, set PYTHONPYCACHEPREFIX to a single directory instead: Python keeps caching bytecode at full speed but stores all of it in that one place.
Should I add __pycache__ to .gitignore?
Yes. It is generated output specific to your machine and Python version, so it does not belong in version control. The line __pycache__/ in .gitignore is standard in nearly every Python project.
Is it safe to delete __pycache__ inside a virtual environment or site-packages?
Yes, the same rule applies: the bytecode regenerates on the next import. Just be careful to delete only the __pycache__ folders, not the virtual environment itself, which takes real effort to recreate.
Related folders
- How to Clear the pip Cache on Your Mac (and Why It's Safe to Delete)
- Can I Delete the venv Folder? Yes, With One Check First
- Can I delete .pytest_cache? Yes, and here's what it does
- Can I delete .mypy_cache? Yes, it's safe
- Can I delete .ruff_cache? Yes, it's safe
- Can I Delete the .tox Folder? Yes, It's Disposable