Is there a way to compile a Python .py file from the command-line without executing it?
I am working with an application that stores its python exte
In addition to choose the output location of pyc (by @Jensen Taylor's answer), you can also specify a source file name you like for traceback if you don't want the absolute path of py file to be written in the pyc:
python -c "import py_compile; py_compile.compile('src.py', 'dest.pyc', 'whatever_you_like')"
Though "compileall -d destdir" can do the trick too, it will limit your working directory sometimes. For example, if you want source file name in pyc to be "./src.py", you have to move working directory to the folder of src.py, which is undesirable in some cases, then run something like "python -m compileall -d ./ ."