tensorflow-2.7-M1-安装依赖openblas问题
问题描述
安装过程
conda create -n conda-forge-tensorflow conda-forge::tensorflow
conda info -e
conda activate conda-forge-tensorflow
pip install ipython
python -c 'import tensorflow; print(tensorflow.__version__)'
先说结论
- conda 安装tensorflow,依赖numpy;numpy依赖openblas;默认没有安装。
- 手动安装openblas不完全,需要手动配置链接库软链
- 关键信息:
conda install openblas
# 建立软链
ln -s libopenblas.dylib libopenblas_vortexp-r0.3.17.dylib
遇到问题
Traceback (most recent call last):
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module>
from . import multiarray
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
Referenced from: /Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
Reason: tried: '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/bin/../lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/bin/../lib/libcblas.3.dylib' (no such file), '/usr/local/lib/libcblas.3.dylib' (no such file), '/usr/lib/libcblas.3.dylib' (no such file)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 41, in <module>
from tensorflow.python.eager import context
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/tensorflow/python/eager/context.py", line 30, in <module>
import numpy as np
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/__init__.py", line 150, in <module>
from . import core
File "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/bin/python"
* The NumPy version is: "1.21.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
Referenced from: /Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
Reason: tried: '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/bin/../lib/libcblas.3.dylib' (no such file), '/Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/bin/../lib/libcblas.3.dylib' (no such file), '/usr/local/lib/libcblas.3.dylib' (no such file), '/usr/lib/libcblas.3.dylib' (no such file)
排查
- 因为numpy需要线性计算库依赖,openblas相关
- 但conda中没有,用如下命令安装:
conda install openblas
- 确认安装结果:
conda list | grep blas
blas 1.0 openblas defaults
libblas 3.9.0 11_osxarm64_openblas conda-forge
libcblas 3.9.0 11_osxarm64_openblas conda-forge
liblapack 3.9.0 11_osxarm64_openblas conda-forge
libopenblas 0.3.17 h9886b1c_1 defaults
openblas 0.3.17 hca03da5_1 defaults
openblas-devel 0.3.17 hca03da5_1 defaults
ll /Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib
lrwxr-xr-x 1 enzhao enzhao 33B 3 16 18:22 /Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib -> libopenblas_vortexp-r0.3.17.dylib
- 再次导入问题依旧,排查
libopenblas_vortexp-r0.3.17.dylib
文件,发现不存在。 - 建立软链:
cd /Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib
# 建立软链
ln -s libopenblas.dylib libopenblas_vortexp-r0.3.17.dylib
# 确认文件正常
less /Users/enzhao/suanec/libs/miniconda3/envs/conda-forge-tensorflow/lib/libcblas.3.dylib
- 重新导入,已正常:
python -c 'import tensorflow; print(tensorflow.__version__)'
2.7.0
澄轶: suanec -
http://www.cnblogs.com/suanec/
友链:marsggbo
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
点个关注吧~
http://www.cnblogs.com/suanec/
友链:marsggbo
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
点个关注吧~