15

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Kaje
  • 851
  • 7
  • 18
  • 1
    I think any way you would normally use PySide counts as dynamic linking, even if it's part of the same download. If you build a single file exe (which cx_Freeze doesn't do anyway), some people might call that static linking, but I think most still wouldn't. Go ahead and use it - it's there for people to build Python applications, so if that's what you're doing, you're probably fine. – Thomas K Jun 11 '15 at 03:48
  • Thank you Thomas. You mean, even if I build a single file exe (using pyinstaller or anything), It still dynamic linking? If then I can continue with a simple readme file to instructions where to download pyside sources. Is it? – Kaje Jun 11 '15 at 04:43
  • I think most people would say that's still dynamic linking, and what you propose should be fine. If you're worried, ask the [PySide mailing list](http://lists.qt-project.org/mailman/listinfo/pyside) about it - it's their interpretation that's important. But I'd be very surprised if they thought that wasn't good enough. – Thomas K Jun 11 '15 at 19:18
  • Thank you Thomas. I will clear those with pyside mailing list and reply here. It'll be useful to most of the python developers. – Kaje Jun 12 '15 at 01:25

1 Answers1

4

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.

Kaje
  • 851
  • 7
  • 18