Recompile All Python Files in Directory

Recompile All Python Files in Directory

I have a Python directory with a number of .py files. I recently compiled them into .pyc files using python -m compileall. I have now changed some of the source files and would like to recompile, writing over the old .pyc files.

Is there a quick way to do this from the command line without having to manually delete all existing .pyc files?

2 Answers

You just have to run python -m compileall again. It will overwrite older .pyc files. You can pass it the -f switch to force rebuild even if timestamps are up to date (as per the documentation).

When the source code has changed, new .pyc files are automatically created when you run the program again. Therefore I wouldn't worry about compiling, but focus your attention on the code itself.. :)

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.