What is the process of compilation and linking in python?

Hi, I want to know the process of compilation and linking in python

1 - Python is an interpreted language, so I am not sure exactly what you mean by “compilation and linking” in the context of Python;

2 - Nonetheless, it would depend on which interpreter we are talking about. Are you studying one in particular?

1 Like

Variants of Python Jython, IronPython, CPython abound and no doubt embedded and static incarnations do to. Is this what sparked the question Jhon? I’m no Pythonista at all, but I’ll explain how I interpret this.
This is probably a question for SO, but the basics of it is, that Python is fundamentally a script/interpreted language which compiles files (modules) into a form the interpreter can run and these are “pickled” as objects in .pyc (cache) files. The cache files speed up load times for the parser. The concept of “linking” never occurs, because nothing in Python is truly static (in my mind at least).

“Compiled” Python is a actual system/tool which wraps the interpreter itself and all of these pickled modules into an archive which itself is built into a compiled application. These binaries are basically a “manifest” of all the modules the compiled app needs, it’s not “linked”. Compiled “binaries” is not a common usage of Python though, I’m assuming this is not what your question was. Because that’s not how "compiled-python binaries actually work. But are probably the only time “linking” as a concept becomes related to Python, but they are not the same thing. Remember that there are different contexts to understand the term “linking”, linking statically (compile-time) linking dynamically (at runtime) and of course the OS loader fixups which “locate” libraries in application frameworks that for instance rely on those dynamically linked libraries.

One thing to always remember, is that in Python everything is an object: methods, classes, variables, modules all objects, and as such a python “program” can never assume that a variable contains an integer, a function reference, or a class reference. Because this can change at any time. You cannot really think of Python modules and object libraries (libs, dlls or .so files) as similar things.

Sorry not able to answer to be honest. I see Python as a interpreted language being particularly powerful, because it inherently deals with interfaces and “API’s” changing over time which a “linked” program cannot do as fluidly as Python does. I suppose the best answer is: No. But it’s always best to think of Python code as “interpreted” at all times until you get in under the hood and understand the optimizations in the engine itself. @joaofarias has pretty much explained it in a one liner above. :blush:

A slight nit pick, but PYC files are “marshaled” and not “pickled”