Python Forum
Did interpreter 'compile' all import modules(from thrid-party) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Did interpreter 'compile' all import modules(from thrid-party) (/thread-30361.html)

Pages: 1 2


RE: Did interpreter 'compile' all import modules(from thrid-party) - jamesyuan - Oct-19-2020

(Oct-19-2020, 02:11 AM)bowlofred Wrote: Python source code (normally found in a .py file) is parsed and turned into bytecode by the interpreter. Then the python virtual machine executes the bytecode.

If this python code is a module (not a script), then the bytecode step is saved as a .pyc file. Future runs can load the pre-compiled bytecode for faster startup (but not faster execution).

If you want to import code from another language (like C/C++ or whatever) into a python project, you can do so. This will normally require compile to machine code and create a .so or .pyd file. These are not python bytecode and are not run by the python virtual machine, but called out to like any other shared library or DLL.

These binary extensions tend to be avoided when possible because the code is hardware or OS specific and can't be run by any python interpreter, but might be necessary for speed or for access to existing (non-python) code.

Big Grin Big Grin Big Grin Appreciation