What do the python file extensions, .pyc .pyd .pyo stand for?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Cosmic Puzzle
--
Chapters
00:00 What Do The Python File Extensions, .Pyc .Pyd .Pyo Stand For?
00:21 Accepted Answer Score 561
02:41 Answer 2 Score 279
04:16 Answer 3 Score 1
04:43 Thank you
--
Full question
https://stackoverflow.com/questions/8822...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pyc
#avk47
ACCEPTED ANSWER
Score 561
.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*.pycfile 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*.pycfiles 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-dll
Also 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)
- When the Python interpreter is invoked with the -O flag, optimized code is generated and stored in ‘.pyo’ files. The optimizer currently doesn't help much; it only removes assert statements. When -O is used, all bytecode is optimized; .pyc files are ignored and .py files are compiled to optimized bytecode.
- Passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only
__doc__strings are removed from the bytecode, resulting in more compact ‘.pyo’ files. Since some programs may rely on having these available, you should only use this option if you know what you're doing.- A program doesn't run any faster when it is read from a ‘.pyc’ or ‘.pyo’ file than when it is read from a ‘.py’ file; the only thing that's faster about ‘.pyc’ or ‘.pyo’ files is the speed with which they are loaded.
- 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. It is also possible to name a ‘.pyc’ or ‘.pyo’ file directly on the command line.
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.
ANSWER 2
Score 279
- .py - Regular script
- .py3 - (rarely used) Python3 script. Python3 scripts usually end with ".py" not ".py3", but I have seen that a few times
- .pyc - compiled script (Bytecode)
- .pyo - optimized pyc file (As of Python3.5, Python will only use pyc rather than pyo and pyc)
- .pyw - Python script to run in Windowed mode, without a console; executed with pythonw.exe
- .pyx - Cython src to be converted to C/C++
- .pyd - Python script made as a Windows DLL
- .pxd - Cython modern header for use with
cimports. - .pxi - Cython legacy header for raw text
includes. - .pyi - Stub file (PEP 484)
- .pyz - Python script archive (PEP 441); this is a script containing compressed Python scripts (ZIP) in binary form after the standard Python script header
- .pyzw - Python script archive for MS-Windows (PEP 441); this is a script containing compressed Python scripts (ZIP) in binary form after the standard Python script header
- .py[cod] - wildcard notation in ".gitignore" that means the file may be ".pyc", ".pyo", or ".pyd".
- .pth - a path configuration file; its contents are additional items (one per line) to be added to
sys.path. Seesitemodule. - .egg - special zip used for distribution/import, mostly obsolete since PEP 427
- .whl - special zip used for distribution only, widely used by
pip
A larger list of additional Python file-extensions (mostly rare and unofficial) can be found at http://dcjtech.info/topic/python-file-extensions/
ANSWER 3
Score 1
.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.