在OSX上使用PySide加载库未加载错误

时间:2017-07-19 01:40:06

标签: python macos install-name-tool

我将PySide的下载副本移出其原始安装位置(/Library/PySide/2.7/site-packages/PySide)到网络上的某个位置,因此脚本可以访问它。但是,我开始得到一个未加载的图书馆"错误。我在桌面上制作了一份副本进行测试:

Traceback (most recent call last):
  File "test_pyside_imports.py", line 2, in <module>
    import PySide.QtCore
ImportError: dlopen(/Users/user/Desktop/PySide_OSX/PySide/QtCore.so, 2): Library not loaded: /Library/Python/2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib
  Referenced from: /Users/user/Desktop/PySide_OSX/PySide/QtCore.so
  Reason: image not found

之前我遇到过这个问题,我确信我用一个刚刚运行install_name_tool的bash脚本修复了它:

#! /usr/bin/env bash
install_name_tool -change @rpath/libpyside-python2.7.1.2.dylib ./PySide/libpyside-python2.7.1.2.dylib ./PySide/QtCore.so
install_name_tool -change @rpath/libshiboken-python2.7.1.2.dylib ./PySide/libshiboken-python2.7.1.2.dylib ./PySide/QtCore.so

但是,出于某种原因,脚本似乎无法解决问题,QtCore.so仍然在原始位置查找库。我检查了文件的权限,并仔细检查了脚本中的路径。对我失踪的事情有任何想法吗?

感谢。

修改

越来越近了。

#! /usr/bin/env bash
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib ./PySide/libpyside-python2.7.1.2.dylib ./PySide/QtCore.so
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib ./PySide/libshiboken-python2.7.1.2.dylib ./PySide/QtCore.so

当我将上述内容作为bash脚本运行然后尝试进行导入时,我收到一个新错误:

D25MG1AZF8J8:PySide_OSX spearsc$ python test_pyside_imports.py 
Traceback (most recent call last):
  File "test_pyside_imports.py", line 2, in <module>
    import PySide.QtCore
ImportError: dlopen(/Users/spearsc/Desktop/PySide_OSX/PySide/QtCore.so, 2): Library not loaded: ./PySide/libpyside-python2.7.1.2.dylib
  Referenced from: /Users/spearsc/Desktop/PySide_OSX/PySide/QtCore.so
  Reason: unsafe use of relative rpath ./PySide/libpyside-python2.7.1.2.dylib in /Users/spearsc/Desktop/PySide_OSX/PySide/QtCore.so with restricted binary

我认为我的第一个bash脚本的问题是旧路径不存在而被忽略。现在,我需要再次尝试,但使用绝对路径。

1 个答案:

答案 0 :(得分:0)

这就是诀窍。我必须在我的bash脚本中使用绝对路径。所有bash脚本都运行'install_name_tool'来将旧路径更改为新路径。

#! /usr/bin/env bash
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libpyside-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/QtCore.so
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libshiboken-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/QtCore.so
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libpyside-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libshiboken-python2.7.1.2.dylib
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libshiboken-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libshiboken-python2.7.1.2.dylib
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libpyside-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libpyside-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libpyside-python2.7.1.2.dylib
install_name_tool -change /Library/Python/2.7/site-packages/PySide/libshiboken-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libshiboken-python2.7.1.2.dylib /Users/spearsc/Desktop/PySide_OSX/PySide/libpyside-python2.7.1.2.dylib

请记住,代码片段只会更改QtCore.so,libshiboken-python2.7.1.2.dylib和libpyside-python2.7.1.2.dylib的路径。您还需要为PySide文件夹中的所有.so文件运行'install_name_tool'。最后,我的bash脚本长约37-38行。