Debug Mac M1/M2 tensorflow:Could not find a version that satisfies the requirement tensorflow

报错信息

在M1芯片/M2芯片的Mac中安装tensorflow报错

ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow

  • 检查python版本
    • 3.9没问题
  • 检查pip版本
    • 最新没问题
  • 检查镜像地址
    • 依次试了豆瓣、中科大、阿里云都失败
  • 安装了torch
    • 成功
  • 猜测是因为Mac M1芯片导致的,搜索后采用如下方式成功
python3 -m pip install tensorflow-macos

错误2

然后就马上发现了新的错误
Debug Mac M1/M2 tensorflow:Could not find a version that satisfies the requirement tensorflow_第1张图片
一屏幕的报错

  • distutils.errors.CompileError: command ‘/usr/bin/gcc’ failed with exit code 1
  • error: legacy-install-failure

安装

conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

因为才知道M1安装起来有多坑,大意了。应该一开始就参考这里: https://developer.apple.com/metal/tensorflow-plugin/

错误3

当然紧接着安装成功了,但是import的时候又报错了
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

查到的方式是更新numpy

pip install numpy --upgrade

重新退出python之后确实可以了

Mac M1 opencv安装

用conda,不要用pip

conda install -c conda-forge opencv

conda安装的没有问题,而pip安装的就报错

ImportError: dlopen(/Users/longxingtan/opt/anaconda3/envs/segment/lib/python3.8/site-packages/cv2/cv2.cpython-38-darwin.so, 0x0002): Library not loaded: '/opt/homebrew/opt/ffmpeg/lib/libavcodec.58.dylib'
  Referenced from: '/Users/longxingtan/opt/anaconda3/envs/segment/lib/python3.8/site-packages/cv2/cv2.cpython-38-darwin.so'
  Reason: tried: '/opt/homebrew/opt/ffmpeg/lib/libavcodec.58.dylib' (no such file), '/usr/local/lib/libavcodec.58.dylib' (no such file), '/usr/lib/libavcodec.58.dylib' (no such file)

你可能感兴趣的:(tensorflow,python,人工智能)