[Tutor] Dynamic linking vs Static linking of libraries in python

Steven D'Aprano steve at pearwood.info
Wed Jun 17 15:55:18 CEST 2015


On Wed, Jun 17, 2015 at 07:52:46AM +0000, Velummaylum Kajenthiran via Tutor wrote:

> Dear Sir/MadamI know the difference between static and dynamic linking 
> in C or C++. But what does it mean this in Python? 

Nothing. It isn't relevant to pure Python code. All Python code is 
dynamically linked in the C sense.

The *Python interpreter* itself may be a C application, and like any 
other C application it might use static or dynamic linking to its own 
libraries.

> Since it's just an 
> interpreter, and only having one style of import mechanism of modules, 
> how this make sense?

It doesn't. Python module imports are always dynamic.


> If I freeze my python application with 
> PyInstaller, Is it a kind of dynamic linking? Because, users can 
> replace that library by themselves in order to run my application with 
> different versions of libraries.What would be the meaning for this, if 
> I freeze this as one file exe? 

PyInstaller makes a copy of the Python interpreter and all the modules 
you use, places those copies into a single directory, and wraps that 
directory into a stand-alone executable file.

http://pythonhosted.org/PyInstaller/#id11

As far as your Python app is concerned, nothing has changed. It just 
runs under a Python interpreter, and sees the same modules as before. 
The only difference is that it is a copy of the interpreter, and a 
copy of those modules.


> In this case, users can not replace the 
> dlls in order to run my app with different versions of PySide 
> libraries.Actually my problems is, I'm using PySide library (with LGPL 
> v2.1) to develop python GUI application. Library says, I should 
> dynamically link to library to obey their legal terms (same as Qt). In 
> this case, how do I link PySide dynamically?

You should probably ask on a PySide forum, but as far as I can tell you 
don't have to do anything special with your Python code. If you are 
using C or C++ code and linking to the PySide libraries, then you have 
to link dynamically in the C/C++ compiler.

But I'm not an expert. You really ought to ask on a PySide forum.



-- 
Steve


More information about the Tutor mailing list