安装过程
1、首先安装anaconda3,下载地址:https://www.anaconda.com/download/
2、使用下面的命令创建tensorflow环境
conda create -n tensorflow python=3.5.2
可以直接在cmd中键入python,就能看到当前python的版本,博主是3.5.2,于是令python=3.5.2
3、激活tensorflow环境
activate tensorflow
4、找到要安装的 tensorflow 的版本
anaconda search -t conda tensorflow-gpu
找到适合 win10的安装版本,并复制其名称,这里选择win-64对应的版本,其名称为nwani/tensorflow-gpu,于是用下面的代码获取该版本的安装方法
anaconda show nwani/tensorflow-gpu
5、按照获取的安装方法进行安装,如图,键入上面的命令后出现以下信息
将该命令在cmd中键入
conda install --channel https://conda.anaconda.org/nwani tensorflow-gpu
回车后即安装完毕。
报错及解决方案
1、输入 install tensorflow as tf 后报错 ImportError: No module named 'tensorflow'
解决方案:键入以下代码
pip install --upgrade -I setuptools
运行成功后,键入
pip install --upgrade --ignore-installed tensorflow
即可。
2、按照上述方法试验后,重新输入 install tensorflow as tf 后报错
ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/ubuntu/.local/lib/python3.5/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version
解决此问题的一种方法是重复卸载numpy,直到找不到,然后重新安装此版本
即重复键入
pip uninstall numpy
直至显示No modules或者not installed以后,再重新安装更新tensorflow
pip install --upgrade --ignore-installed tensorflow
3、输入 install tensorflow as tf 后报错 ModuleNotFoundError: No module named '_pywrap_tensorflow_internal
解决方案:swig是一个python到c/c++的依赖包,该错误应该是缺少依赖,安装Microsoft Visual C++ 2015 Redistributable即可
安装地址https://www.microsoft.com/en-us/download/details.aspx?id=53587
安装后再次测试install tensorflow as tf即可成功