TensorFlow 2.5 Mac M1安装问题与NumPy library/Conda env的兼容性

2024-06-30 08:48:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用针对M1(MacBookPro-2020)优化的新Tensorflow 2.5创建conda环境时遇到了一个巨大的问题

我遵循这些步骤:

  1. https://github.com/conda-forge/miniforge安装针对arm64处理器优化的miniforge3
  2. 然后在终端上创建一个conda env(“conda create--name tf25”和“conda activate tf25”)
  3. 在我遵循苹果指南(https://developer.apple.com/metal/tensorflow-plugin/)之后

结果是:

enter image description here

最后,当我尝试导入NumPy包时,出现了一个导入错误

import numpy

Traceback (most recent call last): File "/Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/init.py", line 22, in from . import multiarray File "/Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in from . import overrides File "/Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in from numpy.core._multiarray_umath import ( ImportError: dlopen(/Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: @rpath/libcblas.3.dylib Referenced from: /Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/init.py", line 140, in from . import core File "/Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/init.py", line 48, in 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/antoniosquicciarini/miniforge3/envs/tf25/bin/python"
  • The NumPy version is: "1.19.5"

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/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: @rpath/libcblas.3.dylib Referenced from: /Users/antoniosquicciarini/miniforge3/envs/tf25/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so

Reason: image not found

我已经试过:

  • 使用pip安装numpy
  • 安装较低版本的python(3.8)

我认为新的TensorFlow-an NumPy库存在兼容性问题,因为直到今天我还在另一个conda环境中使用了TensorFlow 2.4


Tags: fromcorenumpylibpackageslinesiteconda