Erdal TAŞKESEN Erdal TAŞKESEN

How to remove __pycache__ folders and .pyc files

20 February 2018

These folder and files are generated by python. You should add these to your VCS’s ignore file. But if you need to clean these manually, you can do with the command below:

find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf

This command will remove all files that end with .pyc and __pycache__ folder recursively in the current directory. If you are using this command a lot, you should think about adding it to your *sh alias list.

Note: For Python 3, you only need to remove __pycache__ folder because .pyc files are inside them.

Alternative: You can prevent the generation of the file in the development using the environment variable below:

export PYTHONDONTWRITEBYTECODE=""

SOURCES:

Tags: python