学计算机的那个

不是我觉到、悟到,你给不了我,给了也拿不住;只有我觉到、悟到,才有可能做到,能做到的才是我的.

0%

Mac install TensorFlow

环境:
Mac OS Monterey 12.5.1
MacBook Air (M1, 2020)
Xcode 14.1
Python 3.11.5

直接下载提示

科学上网下,执行pip3 install tensorflow

报错:

1
2
3
4
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
unknown package:
Expected sha256 7b3e4e01721bfc0105c99275113531a659e89fd6512340a7b8970593676e0114
Got 0d24ac38699964b36fde01eeae12a7350d0a49054e233af13d10f118364a2517

尝试解决:终端使用代理

开启Terminal Proxy 失败

这里的失败是curl不开代理时返回正常,开启代理时无反应,长时间后返回错误

curl: (97) Received invalid version in initial SOCKS5 response

原因:curl没有配置代理或者代理配置有误。道理跟aptwget不能联网差不多。

解决

1
2
3
4
5
# 查看curl代理配置(如果没有这个文件会自动新建)
$ sudo vi ~/.curlrc

# 更改为正确的配置,加入你的代理IP地址:
proxy = "http://10.xxx.xxx.xxx:8080"

开启代理后 curl能正常返回

开启Terminal Proxy代理后 失败

Missing dependencies for SOCKS support

1
2
jack:~/ $ pip3 install tensorflow                                    [21:23:07]
ERROR: Could not install packages due to an OSError: Missing dependencies for SOCKS support.

解决:

1
2
# unproxy
pip install pysocks

代理运行正常

Error: No matching distribution found for tensorflow

暂时无可用版本,尝试降低Python版本,安装python版本管理工具pyenv

pyenv py版本管理工具

基本使用

1
2
3
pyenv versions # 显示已安装版本
pyenv install -l # 显示可下载版本
pyenv --version # 当前正在使用的版本

Mac安装多个版本py环境时,想要执行哪个版本的pip install需要输入pip的完整路径,避免混淆

全局更改

1
2
pyenv global 3.10.4 #使用该版本
pyenv global system #使用系统版本

局部环境

1
2
3
cd ProjcetSpecial #进入局部py环境项目路径
pyenv local 3.7
ll #显示所有文件 .python-version (3.7)

Pycharm Add

底部添加新的解释器 -> Virtualenv Environment -> Existing ->path/bin/python

You should select “Existing environment”, and specify path to python binary from that environment.

Success

尝试操作

  • [ ] 降低Py版本 python 3.9.5
  • [ ] 安装python -m pip install --upgrade --force-reinstall tensorflow-metal 成功
  • [ ] 解决hash不匹配pip3 install --user --upgrade tf-nightly --no-cache-dir 无效
  • [x] 关闭代理客户端
1
2
3
pip install tensorflow-macos
...
Successfully installed MarkupSafe-2.1.3 absl-py-2.0.0 astunparse-1.6.3 cachetools-5.3.1 certifi-2023.7.22 charset-normalizer-3.3.0 flatbuffers-23.5.26 gast-0.5.4 google-auth-2.23.2 google-auth-oauthlib-1.0.0 google-pasta-0.2.0 grpcio-1.59.0 h5py-3.9.0 idna-3.4 importlib-metadata-6.8.0 keras-2.14.0 libclang-16.0.6 markdown-3.5 ml-dtypes-0.2.0 numpy-1.26.0 oauthlib-3.2.2 opt-einsum-3.3.0 packaging-23.2 protobuf-4.24.4 pyasn1-0.5.0 pyasn1-modules-0.3.0 requests-2.31.0 requests-oauthlib-1.3.1 rsa-4.9 tensorboard-2.14.1 tensorboard-data-server-0.7.1 tensorflow-estimator-2.14.0 tensorflow-io-gcs-filesystem-0.34.0 tensorflow-macos-2.14.0 termcolor-2.3.0 typing-extensions-4.8.0 urllib3-2.0.6 werkzeug-3.0.0 wrapt-1.14.1 zipp-3.17.0
1
2
3
4
pip install tensorflow
...
Installing collected packages: tensorflow
Successfully installed tensorflow-2.14.0

tensorflow-metal,它是一个TensorFlow的后端,使用苹果的Metal图形API来加速神经网络计算。 Metal是一种高性能图形和计算API,专门为苹果设备的GPU设计,可以实现更快的神经网络计算

猜测正确操作是关闭了代理客户端 + 降低py版本起了作用,待后续验证

参考

  1. 安装TensorFlow报错:No matching distribution found for tensorflow
  2. curl: (7) Received invalid version in initial SOCKS5 response. curl: (5) Could not resolve proxy:
  3. Missing dependencies for SOCKS support
  4. google:tensorflow-metal是什么
  5. pycharm when using pyenv does not pickup packages
  6. pycharm when using pyenv:video