PySide / Qt Import Error

2020-02-23 06:33发布

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

5条回答
一纸荒年 Trace。
2楼-- · 2020-02-23 06:51

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.

查看更多
Animai°情兽
3楼-- · 2020-02-23 07:01

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
查看更多
等我变得足够好
4楼-- · 2020-02-23 07:04

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

查看更多
叛逆
5楼-- · 2020-02-23 07:16

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

查看更多
Explosion°爆炸
6楼-- · 2020-02-23 07:16

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/

查看更多
登录 后发表回答