0

我将下载的 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 脚本的问题是旧路径不存在并且被忽略了。现在,我需要再试一次,但使用绝对路径。

4

1 回答 1

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 行。

于 2017-07-19T17:21:31.913 回答