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

然后就马上发现了新的错误
在这里插入图片描述
一屏幕的报错

  • 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)

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
ERROR: Could not find a version that satisfies the requirement tensorflow usually occurs when the specified version of TensorFlow is not available or compatible with the current environment. To resolve this issue, you can try the following steps: 1. Check your Python version: Make sure you have a compatible version of Python installed. TensorFlow has specific version requirements, so ensure that your Python version meets the requirements specified by TensorFlow. 2. Update pip: Run the command `pip install --upgrade pip` to update your pip package manager. This ensures that you have the latest version of pip installed, which may resolve any compatibility issues. 3. Check your internet connection: Ensure that you have a stable internet connection. Sometimes, this error can occur if the required TensorFlow package is not available for download. 4. Specify a different TensorFlow version: If you are trying to install a specific version of TensorFlow and it is not available, you can try installing a different version. Use the command `pip install tensorflow==<version>` to install a specific version of TensorFlow. 5. Use a virtual environment: It is recommended to use a virtual environment to manage your Python packages. Create a new virtual environment and try installing TensorFlow within that environment. If none of the above steps work, please provide more details about your environment, such as the operating system, Python version, and any other relevant information. This will help in providing a more specific solution.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YueTann

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值