简体   繁体   English

库 (dylib) 未加载 - 找不到图像 - Python IDE

[英]Library (dylib) not loaded - image not found - Python IDE

Basically I'm trying to run some Python code from savReaderWriter module in order to create a.sav file ready to open in IBM SPSS.基本上,我试图从 savReaderWriter 模块运行一些 Python 代码,以便创建一个可以在 IBM SPSS 中打开的 .sav 文件。 As a macOS user I needed to run these two lines in the terminal first for the module to work:作为 macOS 用户,我需要先在终端中运行这两行,模块才能工作:

echo 'export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos'  >> ~/.bash_profile
echo 'export LC_ALL=en_US.UTF-8'  >> ~/.bash_profile

Below you can see a piece of code I'm trying to run in Python:下面你可以看到我试图在 Python 中运行的一段代码:

import savReaderWriter

savFileName = "someFile.sav"
records = [['Test1', 1, 1], ['Test2', 2, 1]]
varNames = ['var1', 'v2', 'v3']
varTypes = {'var1': 5, 'v2': 0, 'v3': 0}
with savReaderWriter.SavWriter(savFileName, varNames, varTypes, ioUtf8=True) as writer:
    for record in records:
        writer.writerow(record)

My problem is that while running the code in Python through terminal.app works like a charm and a new.sav file appears, trying to execute the very same code in an IDE (tried PyCharm and Spyder) gives me an error:我的问题是,当通过 terminal.app 在 Python 中运行代码时,就像一个 charm 一样工作并且出现了一个 new.sav 文件,试图在 IDE 中执行完全相同的代码(尝试过 PyCharm 和 Spyder)给我一个错误:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2847, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-94007b092d47>", line 7, in <module>
    with savReaderWriter.SavWriter(savFileName, varNames, varTypes, ioUtf8=True) as writer:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/savWriter.py", line 198, in __init__
    super(Header, self).__init__(savFileName, ioUtf8, ioLocale)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 29, in __init__
    self.spssio = self.loadLibrary()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 117, in loadLibrary
    spssio = self._loadLibs("macos")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 89, in _loadLibs
    return [load(os.path.join(path, lib)) for lib in libs][-1]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 89, in <listcomp>
    return [load(os.path.join(path, lib)) for lib in libs][-1]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicuuc48.1.dylib, 6): Library not loaded: @executable_path/../lib/libicudata48.1.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicuuc48.1.dylib
  Reason: image not found

The module author was unable to help me on this matter, therefore I would be very glad for any suggestions from this community.模块作者无法在这件事上帮助我,因此我很高兴收到这个社区的任何建议。

EDIT (added sys.path):编辑(添加 sys.path):

From terminal:从终端:

 ['',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages',
 '/Users/mg/mne-python']

From IDE:从集成开发环境:

['/Applications/PyCharm.app/Contents/helpers/pydev',
 '/Users/mg/Documents/Python/Projects/MD',
 '/Applications/PyCharm.app/Contents/helpers/pydev',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages',
 '/Users/mg/mne-python',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/extensions',
 '/Users/mg/Documents/Python/Projects/MD']

Regards,问候,

MG名爵

Found the solution!找到解决方案!

Basically I needed to create symbolic links to every dylib that appeared in the error, examples below:基本上我需要为错误中出现的每个 dylib 创建符号链接,示例如下:

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicudata48.1.dylib /usr/local/lib/libicudata48.1.dylib
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicui18n48.1.dylib /usr/local/lib/libicui18n48.1.dylib
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libspssdio.dylib /usr/local/lib/libspssdio.dylib
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libzlib123spss.dylib /usr/local/lib/libzlib123spss.dylib

So theoretically speaking:所以从理论上讲:

sudo ln -s /path/to/original /path/to/symbolic/link

Regards,问候,

MG名爵

I'll add an answer to this question just to make it more generalizable.我将添加这个问题的答案只是为了让它更普遍。 Would have preferred a comment but don't have the rep, While Maciej is entirely correct, and his answer helped me find my problem.本来希望发表评论但没有代表,虽然 Maciej 是完全正确的,但他的回答帮助我找到了我的问题。 savReaderWriter has since been updated. savReaderWriter 已更新。 As of version 3.4.2 there are now 6.dlyb files to be copied over.从版本 3.4.2 开始,现在有 6.dlyb 文件要复制。

Once you have your path to your folder (path is location of your error message), make sure to list ( ls in a terminal window) all files within that folder before creating your symlinks.获得文件夹路径后(路径是错误消息的位置),请确保在创建符号链接之前列出(终端窗口中的ls )该文件夹中的所有文件。 Then create symlinks for each .dylib然后为每个.dylib创建符号链接

Thanks again to Maciej for the great answer!再次感谢 Maciej 的出色回答!

For anyone else who is lazy:对于其他懒惰的人:

ls /Users/your_user/anaconda/envs/quattro8/lib/python2.7/site-packages/savReaderWriter/spssio/macos/ | xargs -I {} sudo ln -s /Users/your_user/anaconda/envs/quattro8/lib/python2.7/site-packages/savReaderWriter/spssio/macos/{} /usr/local/lib/{}

This links all packages in that repo这链接了该仓库中的所有包

You can also specify the path to the libraries within PyCharm, which eliminates the need to create the symbolic links:您还可以在 PyCharm 中指定库的路径,这样就无需创建符号链接:

From the menubar click "Run" -> "Edit Configurations".从菜单栏中单击“运行”->“编辑配置”。 In the left pane select the configuration for your python script (usually PyCharm creates a configuration for each.py-file).在左窗格中选择 python 脚本的配置(通常 PyCharm 会为每个 .py 文件创建一个配置)。 Insert the path to the libraries (shown in the error message) into "Environment Variables".将库的路径(显示在错误消息中)插入“环境变量”。

Example: DYLD_LIBRARY_PATH=/Users/username/miniconda3/envs/savreader/lib/python3.6/site-packages/savReaderWriter/spssio/macos;示例: DYLD_LIBRARY_PATH=/Users/username/miniconda3/envs/savreader/lib/python3.6/site-packages/savReaderWriter/spssio/macos;

Screenshot of PyCharm Run Configuration PyCharm 运行配置截图

After upgrading to Mac OS Catalina, copying all six dylib files to /usr/local/lib/ no longer work (for me at least).升级到 Mac OS Catalina 后,将所有六个 dylib 文件复制到/usr/local/lib/不再有效(至少对我而言)。 To find out what the correct destination was, I did the following:为了找出正确的目的地是什么,我做了以下事情:

  1. Open the ctypes/__init__.py referred in the error stack tree打开错误堆栈树中引用的ctypes/__init__.py
  2. Add print(os.getcwd()) to get the working directory.添加print(os.getcwd())以获取工作目录。 For me, the working directory was /Users/Username/GitHub/myproject对我来说,工作目录是/Users/Username/GitHub/myproject
  3. Since the path in the dylib files is relative to this path ( @executable_path/../lib/ ), the correct destination for the dylib files was /Users/Username/lib由于 dylib 文件中的路径是相对于此路径 ( @executable_path/../lib/ ),因此 dylib 文件的正确目标是/Users/Username/lib

I am not a Mac person, but are you really using Python 3.6?我不是 Mac 用户,但你真的在使用 Python 3.6 吗? Does the savReaderWriter support that version? savReaderWriter 是否支持该版本? I doubt that the I/o module it uses is built for that version.我怀疑它使用的 I/O 模块是为那个版本构建的。

If this works via Terminal but not an IDE, check that the Python search paths are the same.如果这通过终端而不是 IDE 工作,请检查 Python 搜索路径是否相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 库未加载:libssl.1.0.0.dylib原因:找不到图像 - library not loaded: libssl.1.0.0.dylib reason: image not found 库未加载:libboost_python.dylib - Library not loaded: libboost_python.dylib 使用flask_mysqldb获取“库未加载:libssl.1.0.0.dylib”,“原因:找不到图像” - Getting "Library not loaded: libssl.1.0.0.dylib", "Reason: image not found" with flask_mysqldb 库未加载:/usr/local/opt/mysql/lib/libmysqlclient.21.dylib和原因映像未找到 - Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib and Reason image not found 导入 pycurl:未加载库:@rpath/libcrypto.1.1.dylib:原因:找不到图像 - import pycurl: Library not loaded: @rpath/libcrypto.1.1.dylib : Reason: image not found 库未加载:@rpath/libmysqlclient.21.dylib 原因:找不到图像 Django 使用 mysqlclient DB 驱动程序迁移错误和 MySQL 8 with macOS - Library not loaded: @rpath/libmysqlclient.21.dylib Reason: image not found Django migrate error using mysqlclient DB driver and MySQL 8 with macOS 库未加载:@ rpath / libopenblasp-r0.2.19.dylib multiarray.cpython-36m-darwin.so原因:找不到图像 - Library not loaded: @rpath/libopenblasp-r0.2.19.dylib multiarray.cpython-36m-darwin.so Reason: image not found Python:MySQLdb和“未加载库:libmysqlclient.16.dylib” - Python: MySQLdb and “Library not loaded: libmysqlclient.16.dylib” python import pymssql: Library not loaded:libsybdb.5.dylib - python import pymssql : Library not loaded:libsybdb.5.dylib Python mysqldb:未加载库:libmysqlclient.18.dylib - Python mysqldb: Library not loaded: libmysqlclient.18.dylib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM