PyQt4 Need to move DLLs to package root

2019-01-28 06:50发布

问题:

I've used the new installers from http://www.riverbankcomputing.co.uk/software/pyqt/download for Python 2.6 x86_64 and I've a small problem importing PyQt4 in one particular application.

Here's the traceback:

# ERROR : Traceback (most recent call last):
#   File "<Script Block >", line 2, in <module>
#     from PyQt4 import QtCore
# ImportError: DLL load failed: The specified procedure could not be found.
#  - [line 2]

This might look familiar. Fun thing is that in a previous version of the 3d software it does work (and from a standard command line), but not in the new software version. I inspected the sys.path (within the app) in order to see if this path was there: C:\Python26\Lib\site-packages\PyQt4\bin

In both application this path is present.

Finally managed to make it works by copying the DLLs from C:\Python26\Lib\site-packages\PyQt4\bin to C:\Python26\Lib\site-packages\PyQt4

Is there any known reason for this? I've a hard time debugging this thing further (making sure everything is 64 bit, path are correct, etc)

Thanks for your help

回答1:

The problem could be that the PyQt4 installers add the PyQt4\bin directory to the Windows DLL search path. If you have both the 32 bit and the 64 bit versions installed, only one will find the correct set of DLLs.

The solution is to add the following code to each Lib\site-packages\PyQt4_init_.py file:

import os
os.environ['PATH'] = ';'.join((os.path.join(
    os.path.abspath(os.path.dirname(__file__)), "bin"),
    os.environ['PATH']))


回答2:

In my ...\PyQt4\bin folder, there are mainly a few executables and many DLLs, presumably the original Qt ones. You don't use these from Python. You use the .pyd files (which are DLLs under the hood), which are - at least in my installation, Python 3.1 under 32 bit Win7 - in the main directory (just ...\PyQt4) and contain the code that wraps Qt for use from Python.



标签: python pyqt4