I am running mint 13 and have python 3.2 installed using the apt-get package management system. I also have python 2.7 installed along with 3.2 The pycompile seems to be the one that packages python 2.7 code and and throws exceptions for python 3.2 code.
I have looked around and tried to install a few packages, but have not been able to find pycompile for python 3.2. How do I get pycompile work for python 3.2?
py_compileis a stdlib module that can produce byte-code given Python source. It is rarely needed.To compile Python 3 source code you must use py_compile version included with it and not the version from Python 2.7 if you use it from a command-line:
To change the default location where pyc-files are stored you could use
cfileparameter of thepy_compile.compile()function.It might (by a minuscule amount). Python compiler doesn’t do much so it is fast.
Here’s an example how byte-code looks like in a human readable form:
All heavy lifting is left for the python interpreter that interprets the byte-code at runtime.
The docs provide a use-case: a shared directory with Python modules where only curtain users can write. You can disable caching byte-code to disk so it is possible to use py-files that stored in read-only locations without corresponding pyc-files.
Usually the pyc-files are created by building/installation process. If there is no pyc-files they can be created on-the-fly when you import a module: