本文主要是介绍mac 系统下安装tensorflow过程中踩得一些坑,以及自己的解决办法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
mac 系统下pip install tensorflow
1. 速度慢
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
2. 速度上来了,但由于网速不稳定超时了
ERROR: Exception:
Traceback (most recent call last):
File “/Users/mac/anaconda3/envs/tensorflow/lib/python3.5/site-packages/pip/_vendor/urllib3/response.py”, line 360, in _error_catcher
pip --default-timeout=100 install -U tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
3. 前面重复使用了太多次命令了
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.
pip --default-timeout=100 install -U --upgrade tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
4. 安装好后还没高兴太久就又有新的问题出现了
# 导入数据集的时候总是报错
from tensorflow.examples.tutorials.mnist import input_data
Cannot find reference ‘tutorials’ in ‘init.py’
然后去找这方面的解答方案,整了半天后来才发现,原来是自己的tensorflow安装的有问题,连版本都不能输出
import tensorflow as tf#输出版本都一大堆报错,具体就是tensorflow的版本问题
print(tf.__version__)
/opt/anaconda3/envs/py38/bin/python3.8
/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py
–mode=client --port=51645 import sys; print(‘Python %s on %s’ % (sys.version, sys.platform))
sys.path.extend([’/Users/leohao/Documents/ML/ml-python-master’])
Python 3.8.5 (default, Sep 4 2020, 02:22:02) Type ‘copyright’,
‘credits’ or ‘license’ for more information IPython 7.18.1 – An
enhanced Interactive Python. Type ‘?’ for help. PyDev console: using
IPython 7.18.1 Python 3.8.5 (default, Sep 4 2020, 02:22:02) [Clang
10.0.0 ] on darwin runfile(’/Users/leohao/Documents/ML/ml-python-master/ANN/test.py’,
wdir=’/Users/leohao/Documents/ML/ml-python-master/ANN’) Traceback
(most recent call last): File
“/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/init.py”,
line 22, in
from . import multiarray File “/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py”,
line 21, in do_import
module = self._system_import(name, *args, **kwargs) File “/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/multiarray.py”,
line 12, in
from . import overrides File “/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py”,
line 21, in do_import
module = self._system_import(name, *args, **kwargs) File “/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/overrides.py”,
line 7, in
from numpy.core._multiarray_umath import ( File “/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py”,
line 21, in do_import
module = self._system_import(name, *args, **kwargs) ImportError: dlopen(/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so,
2): Library not loaded: @rpath/libopenblas.dylib Referenced from:
/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so
Reason: image not found During handling of the above exception,
…
https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the == following: * The Python version is: ==
Python3.8 from “/opt/anaconda3/envs/py38/bin/python3.8” * The NumPy
version is: “1.19.2” and make sure that they are the versions you
expect. Please carefully study the documentation linked above for
further help. Original error was:
dlopen(/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so,
2): Library not loaded: @rpath/libopenblas.dylib Referenced from:
/opt/anaconda3/envs/py38/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so
Reason: image not found
我的问题,没注意tensorflow的版本兼容性问题:
tensorflow 版本自动下载最新的2.3.1
numpy 版本也自动下载了最新的1.9
python 用的是anaconda创建的3.8
解决方案降低版本:
- 我使用了anaconda创建了新的环境 python 3.5
如果没有使用anaconda的话,那就建议去安一个,不然不好管理python包和版本;
像我这样python3.8安tensorflow出问题,直接再建一个3.5非常方便。- 安装tensorflow 1.14,安完后提示我更新pip,额我顺便更新了一下,其实到这里就已经可以导入成功了,毕竟我的tensorflow版本也成功输出来了
pip --default-timeout=100 install -U --upgrade tensorflow==1.1.4 -i https://pypi.tuna.tsinghua.edu.cn/simplepip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
- 但是还是有些错误,关于这方面的错误是numpy版本问题
FutureWarning: Passing (type, 1) or ‘1type’ as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / ‘(1,)type’.
_np_qint8 = np.dtype([(“qint8”, np.int8, 1)])
要解决的话就先删除numpy 再安装numpy 1.14
pip uninstall numpy
pip install numpy==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
可喜可贺终于成功导入,可以开始机器学习了!
设置全局的源,就不用敲-i https:…
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
这篇关于mac 系统下安装tensorflow过程中踩得一些坑,以及自己的解决办法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!