Daniel Elliott

Fixing pip installation of PySide in OSX

I would consider myself a hobbyist programmer and enjoy quickly trying out ideas and snippets that I find around on the web. That means that I don’t want to mess around for too long getting a development environment set up. Thats why I use homebrew and pip on OSX. They are┬ápackage managers that just downloads software libraries for you and allows you to use them out of the box. Well most of the time.

I’m trying to re-familiarise myself with PySide (an alternative to PyQt, python bindings for Qt). This is a ritual I do every year and promptly forget.

I needed to reinstall some libraries so I did the usual and ran

pip install PySide

Everything ran as expected apart from the error I got when I tried to run an example script.

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

This means that the QtCore.so can’t find the pyside library. This is due to a thing called ‘rpath’ which is something that is embedded in the library file itself that lists the files that it depends on. In this case the path is set wrong (I’m not sure why and it’s something I would like to see fixed in the homebrew package). After some internet searching, I’ve found two solutions.

  1. Set the environment variable DYLD_LIBRARY_PATH in your ~/.bashrc file so that your shell will know explicitly where to look for the library files….export DYLD_LIBRARY_PATH=/usr/local/lib/python2.7/site-packages/PySide
  2. Run the following in your shell to fix the problem in the library files themselves. This goes into the libraries themselves and fixes the path directly….
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtCore.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtCore.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtGui.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtGui.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtOpenGL.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtOpenGL.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtDeclarative.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtDeclarative.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtHelp.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtHelp.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtMultimedia.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtMultimedia.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtNetwork.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtNetwork.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtScript.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtScript.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtScriptTools.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtScriptTools.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtSql.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtSql.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtSvg.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtSvg.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtTest.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtTest.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtUiTools.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtUiTools.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtWebKit.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtWebKit.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtXml.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtXml.so
    sudo install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtXmlPatterns.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/QtXmlPatterns.so
    sudo install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib @loader_path/libshiboken-python2.7.1.2.dylib /usr/local/lib/python2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib

I won’t go into too much detail about rpaths (another post maybe) as I just wanted to record this here so I can refer back to it myself and possibly could help others too.

One thought on “Fixing pip installation of PySide in OSX

Leave a Reply

Your email address will not be published. Required fields are marked *