Compile everything with a one-liner
1st July 2004
The other day, we noticed that the .py files in our main mod_python application at work did not have corresponding compiled .pyc files. mod_python runs as the unprivileged apache user, which on our server doesn’t have the required permissions to write the compiled .pyc files in to the directories in which our code lives.
A bit of digging came up with the compileall module, which provides functions for byte-compiling Python files in bulk. We invoked it using the following shell one-liner, executed at the upper most directory of our code tree:
python2.3 -c "import compileall; compileall.compile_dir('.')"
Executed as root, the result was a full set of .pyc bytecode files.
More recent articles
- Qwen2.5-Coder-32B is an LLM that can code well that runs on my Mac - 12th November 2024
- Visualizing local election results with Datasette, Observable and MapLibre GL - 9th November 2024
- Project: VERDAD - tracking misinformation in radio broadcasts using Gemini 1.5 - 7th November 2024