Safe to Delete

Is It Safe to Delete __pycache__?

Quick Answer: The __pycache__ folder contains compiled Python bytecode designed to make your scripts run faster. It is completely safe to delete.

What is pycache?

If you write code in Python, you have undoubtedly noticed that whenever you run a script, a mysterious __pycache__ folder instantly appears in your directory, cluttering up your workspace. Inside it, you will find files ending in .pyc (Python Compiled).

Why Does It Exist?

Python is an interpreted language, meaning it reads your human-readable source code (.py) and translates it into machine instructions on the fly. This translation takes time.

To speed things up, the first time you run a Python script, the Python interpreter translates your code into intermediate “bytecode” and saves it in the __pycache__ folder as a .pyc file. The next time you run the script, Python completely skips the translation step and just runs the .pyc file, resulting in a noticeably faster startup time.

Can You Delete It?

Yes, it is 100% safe to delete.

The __pycache__ folder contains absolutely no original source code or data. It is purely a performance cache.

How to Delete It (and Stop It)

You can simply right-click and delete the folder at any time.

However, if you want to stop Python from generating these folders entirely (for example, in a small testing environment where you don’t care about the microsecond speed boost), you can set an environment variable in your terminal:

Linux/macOS: export PYTHONDONTWRITEBYTECODE=1

Windows: set PYTHONDONTWRITEBYTECODE=1

What Happens If You Delete It?

Nothing breaks. The very next time you execute your Python script, the interpreter will take a fraction of a second longer to translate your source code, and it will silently regenerate a brand new __pycache__ folder to speed up the next run.

Bottom Line

__pycache__ is a harmless, automatically generated performance booster for Python scripts. It is perfectly safe to delete, and you should always ensure it is added to your .gitignore file so you don’t accidentally upload it to GitHub.

Discussion

Loading authentication...

Related in developer

The AI Engineer's Model Disk Cleanup Guide: Hugging Face, Ollama & PyTorch

The ultimate 1,200-word field guide for AI developers and local LLM hobbyists to reclaim 200GB+ from Ollama, Hugging Face, PyTorch, and vLLM model weights.

Safe to Delete

Android Studio System Index Cache (AndroidStudio Cache)

Android Studio caches Gradle project indexes, VFS caches, and compiler artifacts. Invalidate and clear is safe.

Safe to Delete

Ansible Automation Temp & Fact Cache (~/.ansible/tmp)

Ansible stores temporary playbook execution modules and target host fact JSON caches in ~/.ansible/tmp. Clearing Ansible tmp is safe.

Safe to Delete
Back to all files