21

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

elliot
  • 498
  • 1
  • 4
  • 13
  • Are you actually trying to use both PySide and PyQt in the same app? Because they don't play nicely together. – abarnert Sep 04 '14 at 02:31
  • Also, are you sure you're using the Homebrew Python 2.7 and its pip consistently, and not using Apple's pre-installed Python 2.7 anywhere? – abarnert Sep 04 '14 at 02:32
  • Yes, Pip for Homebrew Python. I've installed many a package with no issue. – elliot Sep 04 '14 at 16:48
  • And you're right, I'm not using PyQt, just PySide and having issues with Qt. I'll fix the title – elliot Sep 04 '14 at 16:48

5 Answers5

15

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.

Leonardo Bernardini
  • 1,076
  • 13
  • 23
  • How do you find the path to the Pyside libraries? – wlad May 28 '16 at 19:11
  • @jkabrg you can do: "find `dirname \`which python\``/.. -name *pyside*so*" . That gets the path to python, goes to the main directory, then uses that as a path for `find` – Efren Jul 07 '16 at 05:23
  • 1
    @Leonardo Bernardini The exported variable should be "DYLD_LIBRARY_PATH" or it won't work on some macs. – Nir Aug 07 '16 at 10:00
13

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

jw.john
  • 362
  • 4
  • 9
  • Thanks a lot! I solved the issue after running your script in the virtualenv path. – ronnefeldt Dec 04 '14 at 06:44
  • 2
    Hmm, doesn't work for me. After a seemingly successful `pip install PySide`, This script gives me an error "The PySide package not installed: None" – Peter Feb 18 '15 at 08:42
  • 3
    The master branch does no longer contain the file linked to above. Here you find the one which worked for me: https://raw.githubusercontent.com/PySide/pyside-setup/1.2.2/pyside_postinstall.py – geo_so Jul 13 '15 at 14:11
  • If you run into an error like "RuntimeError: install_name_tool -change libpyside...returned code 1" after you ran `pyside_postinstall.py -install`, add `sudo` before it and re-run can solve it. – Daniel Aug 06 '15 at 07:37
  • 1
    As of version [1.2.3](https://pypi.python.org/pypi/PySide#id3) (released 2015-10-12), it should no longer be necessary to run the post install script. If you are still getting the error mentioned by OP, this likely isn't the solution. – duozmo Oct 24 '15 at 02:59
  • @Chrispy https://github.com/pyside/packaging/blob/master/setuptools/templates/pyside_postinstall.py – jw.john Oct 29 '18 at 15:22
3

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/

RyanB
  • 707
  • 1
  • 5
  • 18
1

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
johnson
  • 3,729
  • 3
  • 31
  • 32
0

I had a similar problem, on Mavericks using a Brew-installed Qt and virtual environment.

I had to brew reinstall Qt

Then run the pyside_postinstall.py -install

See here: https://github.com/Homebrew/homebrew/issues/27898

alexgoodell
  • 23
  • 1
  • 6