Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PySide / Qt Import Error

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 :)

like image 532
elliot Avatar asked Sep 04 '14 02:09

elliot


People also ask

Is PySide and PYQT the same?

The key difference in the two versions — in fact the entire reason PySide2 exists — is licensing. PyQt5 is available under a GPL or commercial license, and PySide2 under a LGPL license.

What is QT PySide?

PySide is a Python binding of the cross-platform GUI toolkit Qt developed by The Qt Company, as part of the Qt for Python project. It is one of the alternatives to the standard library package Tkinter. Like Qt, PySide is free software.

What is PySide package?

Pyodide is a port of CPython to WebAssembly/Emscripten. Pyodide makes it possible to install and run Python packages in the browser with micropip. Any pure Python package with a wheel available on PyPI is supported. Many packages with C extensions have also been ported for use with Pyodide.

What is the difference between PySide and PySide2?

PySide is a binding to Qt4, whereas PySide2 is a binding to Qt5. or if you want to be prepared for all cases… And there are versions of PySide2 for Python 2.7, too.


4 Answers

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.

like image 195
Leonardo Bernardini Avatar answered Nov 09 '22 21:11

Leonardo Bernardini


if you watch this , you're question will be fixed: https://github.com/pyside/packaging/blob/master/setuptools/templates/pyside_postinstall.py

pyside_postinstall.py -install

like image 21
jawa Avatar answered Nov 09 '22 21:11

jawa


I had a similar issue, and I resolved it by manually using otool -L (as seen in the question) and install_name_tool to update the paths.

install_name_tool -change @rpath/libshiboken.cpython-34m.1.2.dylib /usr/local/lib/python3.4/site-packages/PySide/libshiboken.cpython-34m.1.2.dylib /usr/local/lib/python3.4/site-packages/PySide/QtCore.so

install_name_tool -change @rpath/libpyside.cpython-34m.1.2.dylib /usr/local/lib/python3.4/site-packages/PySide/libpyside.cpython-34m.1.2.dylib /usr/local/lib/python3.4/site-packages/PySide/QtCore.so

I had to do this for several files in the PySide directory before the script would run.

This blog post is a nice reference: http://thecourtsofchaos.com/2013/09/16/how-to-copy-and-relink-binaries-on-osx/

like image 3
RyanB Avatar answered Nov 09 '22 21:11

RyanB


i found a solution here

export DYLD_LIBRARY_PATH=/usr/local/lib/python[version]/site-packages/PySide

for python 3.5 this would be

export DYLD_LIBRARY_PATH=/usr/local/lib/python3.5/site-packages/PySide
like image 1
johnson Avatar answered Nov 09 '22 21:11

johnson