Skip to content
← All Mac folders

Mac folder guide

__pycache__ Folders on Mac: Safe to Delete?

__pycache__

__pycache__ folders hold compiled Python files (.pyc) that let scripts start faster. They are safe to delete, and Python writes them again the next time the code runs. They are rarely large.

Safe to deleteSafe to delete. Python recreates them

What is __pycache__ on a Mac?

Python compiles each module it imports to bytecode and stores it next to the source, in a __pycache__ folder. Each file name includes the Python version.

They are small, but they collect in every project and in every virtual environment. People mostly remove them to tidy a project or to stop committing them to Git.

What’s inside

  • Compiled .pyc files, one per module and Python version

How to clear __pycache__ safely

  1. Open Terminal in the project folder.
  2. List the folders with the first command below.
  3. Delete them with the second command, which only touches folders named __pycache__ under the current folder.
  4. Add __pycache__/ to .gitignore so they stay out of commits.
List (read only, run inside a project)
find . -type d -name __pycache__
Delete (run inside a project)
find . -type d -name __pycache__ -prune -exec rm -rf {} +

When to keep it

  • Nothing. Just run the commands from inside a project, not from your home folder.

Questions people ask

Is it safe to delete __pycache__?+

Yes. Python rebuilds the files the next time it imports the modules.

Can I stop Python creating __pycache__?+

Yes. Set the PYTHONDONTWRITEBYTECODE environment variable, at the cost of slightly slower start times.

Should __pycache__ be in Git?+

No. Add __pycache__/ to your .gitignore.

See which folders fill your Mac

MacZentra, a disk analyzer and storage cleaner for Mac, scans your disk locally and draws it as a Treemap or Sunburst, so a folder like this one shows up with its real size. Scanning and every visualization are free. Cleaning is a one-time $49.99 purchase, and anything you remove goes to the Trash, so it can be restored.

macOS 13 Ventura or later · Apple silicon