Skip to content

Instantly share code, notes, and snippets.

@alberic89
Last active November 2, 2023 12:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
cd env/lib && find -name "*.pyc" -delete && python -OO -m compileall . -j 0 && find . -path "*/__pycache__/*.pyc" -execdir sh -c "mv {} ../\$(basename {} | cut -d'.' -f1).pyc" \; && find -name "*.py" -delete && cd ../..
@alberic89
Copy link
Author

Gain disk space by compiling your python libs.

  • go to env/lib/ directory
  • remove all previous .pyc files
  • generate all .pyc files with the optimisation level 2
  • rename and move the .pyc files for allow python to find them
  • remove all .py files

The .pyc files are not portables between two differents version of Python or two machines.

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