作为tensorflow初学者,想要在MacBook上面成功安装tensorflow中遇到了很多的坎坷。现在已解决问题,特此发布该文章希望能够帮助到更多的人。
根据网上的不断查阅以及翻看其他人的经验贴,在第一次安装时我才用python3.6.8版本安装tensorflow1.12版本,命令为
pip3 install --upgrade tensorflow==1.12
若网速慢可添加清华源镜像,加快下载速度
pip3 install -i http://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow==1.12
而在实际运行代码的过程中,代码显示zsh: illegal hardware instruction错误
随后我找到一个与我情况接近的网页链接,但并未解决我的问题。
在 macbook pro M1 上安装 Tensorflow 时出现“zsh: illegal hardware instruction python” - SegmentFault 思否
因此我找到苹果官方对于tensorflow的安装方式Tensorflow Plugin - Metal - Apple Developer
安装过程中需注意:
- macOS 12.0 or later (Get the latest beta)
- Python 3.8 or later
而我一开始由于下载了python3.6.8的版本,因此需要用到brew命令重新下载3.8以上版本的python。
brew search python
brew install python@3.8
随后刷新一下终端或者重新打开终端应该就更新到3.8版本的python了。如果python版本没有更新,则会在按照苹果官方流程安装过程中报如下图的错误
ERROR: Could not find a version that satisfies the requirement tensorflow(from versions: none)
ERROR: No matching distribution found for tensorflow
这样就可以成功安装tensorflow了。