Skip to content

Instantly share code, notes, and snippets.

@alberic89
Last active April 24, 2025 12:10
Show Gist options
  • Save alberic89/7b972597112478756a157f0ba329db6c to your computer and use it in GitHub Desktop.
Save alberic89/7b972597112478756a157f0ba329db6c to your computer and use it in GitHub Desktop.
Compile python libs in the env
find -name "*.pyc" -delete && python3 -OO -m compileall . -j 0 && find . -path "*/__pycache__/*.pyc" -execdir sh -c "mv {} ../\$(basename {} | cut -d'.' -f1).pyc" \; && find -name "*.py" -delete
@alberic89
Copy link
Author

alberic89 commented Oct 31, 2023

Gain disk space by compiling your python libs.

It will:

  • remove all previous .pyc files
  • generate all .pyc files with the optimisation level 2
  • rename and move the .pyc files to allow python to find them
  • remove all .py files

The .pyc files are not portables between two different versions of Python or two machines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment