What do these python file extensions mean?
.pyc
.pyd
.pyo
What are the differences between them and how are they generated from a *.py file?
.py
: The input source code that you have written.
.pyc
: The compiled bytecode. If you import a module, python will build a .pyc
a file that contains the bytecode to make importing it again later easier(and
faster).
.pyo
: A .pyc
file that was created while optimizations (-O) were on.
.pyd
: A windows DLL file for python.
cimport
s.include
s.sys.path
. See site
module.pip
A larger list of additional Python file-extensions (mostly rare and unofficial) can be found at http://dcjtech.info/topic/python-file-extensions/
.py
: This is normally the input source code that you've written..pyc
: This is the compiled bytecode. If you import a module, python will build a*.pyc
file that contains the bytecode to make importing it again later easier (and faster)..pyo
: This was a file format used before Python 3.5 for*.pyc
files that were created with optimizations (-O
) flag. (see the note below).pyd
: This is basically a windows dll file. http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dllAlso for some further discussion on
.pyc
vs.pyo
, take a look at: http://www.network-theory.co.uk/docs/pytut/CompiledPythonfiles.html (I've copied the important part below)Note:
On 2015-09-15 the Python 3.5 release implemented PEP-488 and eliminated
.pyo
files. This means that.pyc
files represent both unoptimized and optimized bytecode.