当前位置: 首页 > 工具软件 > LibFFI > 使用案例 >

记录一次conda环境报错的解决ImportError:: Library not loaded: @rpath/libffi.7.dylib

郎磊
2023-12-01

问题

    ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libffi.7.dylib
      Referenced from: /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so
      Reason: tried: '/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/lib-dynload/../../libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/lib-dynload/../../libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/bin/../lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/bin/../lib/libffi.7.dylib' (no such file), '/usr/local/lib/libffi.7.dylib' (no such file), '/usr/lib/libffi.7.dylib' (no such file)

`$ /opt/homebrew/Caskroom/miniforge/base/bin/conda install i`

  environment variables:
conda info could not be constructed.
KeyError('pkgs_dirs')

An unexpected error has occurred. Conda has prepared the above report.

实验环境:
MacOS Monterey Apple Silicon M1
Python with mini-forge brew

分析与解决

一开始看了网上一些文章, 很多都是说更新brew, 或者重新安装conda环境之类, 但是我更新之后也没有解决.
网上没有这个问题的同类解法,但是在Stack Overflow里面,我找到了一个类似的解答, 是说Linux下缺失动态链接库的解决方案, 就是设置软链接到缺失的路径下, 于是我照做了, 顺利解决了问题~~

具体方法就是, 找到libffi的安装路径, 我这里用的是原生编译版本的brew安装的libffi, 其路径为/opt/homebrew/Cellar/libffi/3.4.2/lib/libffi.8.dylib, 将其软链接到/opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib, 即可找到.

命令如下:

sudo ln -sf /opt/homebrew/Cellar/libffi/3.4.2/lib/libffi.8.dylib /opt/homebrew/Caskroom/miniforge/base/lib/libffi.7.dylib

最后执行conda install flask, 完美解决~

问题我认为可能出在brew的更新(或者Monterey, conda等的更新), 导致conda找不到libffi链接库.

 类似资料: