安装tensorflow的过程真的道阻且长啊。
1.一开始用的最直接的pip install tensorflow,然后仔细一看,居然是多伦多的库,龟速下载&疯狂断连,可是翻墙是违法的哦!所以我就决定到国内源下;
2.然后就决定是你了,清华源,毕竟清华是中国名校吗,应该不差吧
在cmd调这个命令
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
然后这个下载速度是真的恶,十几KB/s,不晓得是我的问题还是清华源的问题了,后续见真相,而这网速会导致一个问题,那就是
“Read timed out.”
本着经验,我重复下了三次,都是“Read timed out.”
3.接下来,要不换个源,于是换了个豆瓣的源,哇塞十几MB/s,第二步的疑惑有解了(不是我的错)
在cmd调这个命令,不到一分钟安好
pip install -i https://pypi.doubanio.com/simple/ tensorflow
但是咧,在anaconda里面一 import tensorflow
就出现了
ImportError: DLL load failed: 找不到指定的模块。
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
但是实际上是安装成功的,当我输入指令时,tensorflow 库是有的
conda list
然而其中“Failed to load the native TensorFlow runtime.”这句话实际上就是在告诉我,我的电脑环境不配这个版本的,原因可能有很多,我查了一下我的conda版本,这个查询指令是
conda --version
conda 4.8.3
Note: you may need to restart the kernel to use updated packages.
python版本是3.7.4
所以其实就是版本冲突导致的,一开始豆瓣默认下载版本是tensorflow-2.2.0,CPU版的
然后我在下面这个网址,滑动到最下面有python版本对应的tensorflow支持,发现没有2.2.0的说明。
于是我换成了2.0.0版本进行安装后,可以使用安装指令
pip install -i https://pypi.doubanio.com/simple/ tensorflow==2.0.0
如果你们要安装其他版本,请把2.0.0改成对应的版本号,如果要安装GPU版本的,就用这两个指令,版本修改与CPU一样,GPU和CPU的差别也在官网中查看。
tensorflow安装的gpu官方说明
pip install -i https://pypi.douban.com/simple
或
pip install -i https://pypi.doubanio.com/simple/ tensorflow-gpu
下图是我截取的关于window配置的一部分。
如果大家安装还遇到其他问题,欢迎留下评论和解决方法或者私信我,做一个解决集合,争取一篇博客解决tensorflow所有问题!!!