Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 889
rwolst Avatar asked Jul 11 '13 10:07

rwolst


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).

like image 77
Paulo Almeida Avatar answered Sep 20 '22 06:09

Paulo Almeida


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.. :)

like image 33
kramer65 Avatar answered Sep 21 '22 06:09

kramer65