See here:
When a script is run by giving its name on the command line, the bytecode for the script is never written to a ".pyc" or ".pyo" file. Thus, the startup time of a script may be reduced by moving most of its code to a module and having a small bootstrap script that imports that module.
Thus, if you want to create a .pyc
file, you have to import the script, not just run it from the command line. For example, you could do
python -c "import myscript"
instead of doing
python myscript.py