问题:
为什么sklearn无法检测到它对liblapack的依赖,我该如何解决这个问题?
背景:
下面是安装了scikit-learn
的conda环境(torch-nightly
)(注意liblapack
依赖也存在):
(torch-nightly) au@a2 ~ % conda list |grep "scikit-learn"
scikit-learn 1.1.1 py38hc377ac9_0
(torch-nightly) au@a2 ~ % conda list |grep "liblapack"
liblapack 3.9.0 15_osxarm64_openblas conda-forge
字符串
问题:
我在尝试导入sklearn
时得到以下错误:
(torch-nightly) au@a2 ~ % python -c "import sklearn"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/sklearn/__init__.py", line 82, in <module>
from .base import clone
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/sklearn/base.py", line 17, in <module>
from .utils import _IS_32BIT
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 22, in <module>
from scipy.sparse import issparse
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/__init__.py", line 283, in <module>
from . import csgraph
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/csgraph/__init__.py", line 182, in <module>
from ._laplacian import laplacian
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/csgraph/_laplacian.py", line 7, in <module>
from scipy.sparse.linalg import LinearOperator
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/__init__.py", line 120, in <module>
from ._isolve import *
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/_isolve/__init__.py", line 4, in <module>
from .iterative import *
File "/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/_isolve/iterative.py", line 9, in <module>
from . import _iterative
ImportError: dlopen(/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/_isolve/_iterative.cpython-38-darwin.so, 0x0002): Library not loaded: '@rpath/liblapack.3.dylib'
Referenced from: '/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/_isolve/_iterative.cpython-38-darwin.so'
Reason: tried: '/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/_isolve/../../../../../../liblapack.3.dylib' (no such file), '/Users/au/miniconda3/envs/torch-nightly/lib/python3.8/site-packages/scipy/sparse/linalg/_isolve/../../../../../../liblapack.3.dylib' (no such file), '/Users/au/miniconda3/envs/torch-nightly/bin/../lib/liblapack.3.dylib' (no such file), '/Users/au/miniconda3/envs/torch-nightly/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)
型
问题研究:
我确认了“missing”库(liblapack.3.dylib
)实际上存在于错误中显示的位置:
(torch-nightly) au@a2 ~ % ls miniconda3/envs/torch-nightly/lib/liblapack.3.dylib
miniconda3/envs/torch-nightly/lib/liblapack.3.dylib
型
1条答案
按热度按时间xzv2uavs1#
注意事项:这个答案仅适用于
macOS
用户,并且涉及到复制可能不兼容所有版本的sklearn的dilyb。我强烈建议首先尝试重新安装软件包。如果您仍然失败,并且已经达到了愿意尝试任何东西的程度,以下步骤可能会解决问题。我能够通过手动复制必要的
dylib
的副本来解决这个问题。首先:我运行brew install lapack
[注意:对我来说,这个安装的版本(3.11),你可能会在运行命令后得到一个不同的版本]然后我确定了/opt/homebrew/Cellar/lapack/3.11/lib/*
中的所有相关文件:字符串
确定一个我所有python包都会搜索的搜索路径,我使用miniconda来管理我的python环境,对我来说是:
~/miniconda3/envs/maxEnt/lib/
。步骤1:删除此
lib
文件夹中具有匹配名称的所有现有文件。步骤2:复制上面引用的文件。
步骤3:更新这些文件中的所有符号链接(别名)[
.dylib
指向3.11.0.dylib;.3.dylib
指向3.11.0.dylib
]。