PySide / Qt Import Error

elliot picture elliot · Sep 4, 2014 · Viewed 11k times · Source

I'm trying to import PySide / Qt into Python like so and get the follow error:

from PySide import QtCore

ImportError: dlopen(/usr/local/lib/python2.7/site-packages/PySide/QtCore.so, 2): Library not loaded: libpyside-python2.7.1.2.dylib
  Referenced from: /usr/local/lib/python2.7/site-packages/PySide/QtCore.so
  Reason: image not found

I'm running/installed via:

  • Mac OSX 10.9.4 Mavericks
  • Homebrew Python 2.7
  • Homebrew installed Qt
  • Pip installed PySide

The file libpyside-python2.7.1.2.dylib is located in the same path as the QtCore.so file listed in the error message.

All my searches for this particular problem have yielded people trying to package these libraries as part of an app, which I am not doing. I am just trying to run it on my system and yet have this problem. For troubleshooting an app, people suggested oTool; not sure if it is helpful here, but this is the output when I run oTool:

otool -L QtCore.so 
QtCore.so:
    libpyside-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2)
    libshiboken-python2.7.1.2.dylib (compatibility version 1.2.0, current version 1.2.2)
    /usr/local/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.6)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

Any ideas? Thanks in advance :)

Answer

Leonardo Bernardini picture Leonardo Bernardini · Sep 4, 2014

Well, the installer is somewhat broken, because the output from oTool should report a full path to the library (the path should be changed by the Pyside installer using install_name_tool).

Instead of going mad understanding what part of the installer is broken, I suggest you define:

DYLD_LIBRARY_PATH=/your/path/to/pyside/libraries
export DYLD_LIBRARY_PATH

This will force the executable loader to scan for libraries into the path you supply too, even it's not configured by the linker.