What does it mean for statically linking and dynamically linking in Python?

3.5k views Asked by At

I know the difference between static and dynamic linking in C or C++. But what does it mean in Python? Since it's just an interpreter, and only having one style of import mechanism of modules, how does this make sense?

If I freeze my Python application with cx_freeze by excluding a specific library, is it a kind of dynamic linking? Because, users have to download and install that library by themselves in order to run my application.

Actually my problem is, I'm using the PySide library (with LGPL v2.1) to develop a Python GUI application. The library says I should dynamically link to the library to obey their legal terms (same as Qt). In this case, how do I link to PySide dynamically?

1

There are 1 answers

0
Kaje On BEST ANSWER

In python there's no static linking. All the imports requires the correct dependencies to be installed on our target machine. The choice of the version of such libraries are in our decision.

Now let's come to the binary builders for python. In this case, we'll have to determine the linking type based on the GNU definitions. If the user can replace the dependency as he likes, it's dynamic. If the dependency is attached together with the binary itself, it's static linking. In case of cx_freeze or pyinstaller, if we build this as one file, it's static linking. If we build this in normal mode where all the dependencies are collected as separate files, it's dynamic linking. Idea is, whether we can replace the dependency in target machine or not.