上一篇文章我们讲了Cuda、cuDNN和Anaconda的安装,下面说一下tensorflow以及spyder的安装和使用。
(1)打开Anaconda Prompt,输入清华仓库镜像,这样更新会快一些:
- 1
- 2
- 1
- 2
(2)同样在Anaconda Prompt中利用Anaconda创建一个python3.5的环境,环境名称为tensorflow ,输入下面命令:
- 1
- 1
运行 开始菜单->Anaconda3—>Anaconda Navigator
,点击左侧的Environments
,可以看到tensorflow
的环境已经创建好了。
(3)在Anaconda Prompt中启动tensorflow环境:
- 1
- 1
(4)安装GPU版tensorflow注:当不使用tensorflow时,关闭tensorflow环境,命令为:
deactivate
pip install --ignore-installed tensorflow-gpu
只需这么简短的命令即可,不需要,一大堆的命令,
如:pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/win/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
这样的命令反而不好,除非需要某个特定版本的tensorflow,否则只需最简单的那个即可,那样就是下载安装最新版的。
(5) 测试
测试一行命令既可:
>> python #进入python,会显示python的版本,这里定然是 3.52
>>import tensorflow as tf
注:我的报错:
C:\Users\Administrator>Python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
>>>
解决方法是:把cuDNN的一个dll文件改下名,如下图:
如果上面的命令没出差错,那么tensorflow就是算是装成功了。
但是很遗憾,到这里为止,仍然是命令行的输入,而不能使用spyder。
在spyder下 import tensorflow as tf 报错:No module named tensorflow
退出pyth环境, ctrl+z 回车
4 安装spyder插件
命令 conda install spyder
后面就是等待了,完成后生成一个spyder(tensorflow-cpu)
5 启动spyder
若是直接启动tensorflow-cpu 是不会成功的。有人在这里将Anaconda3\envs\tensorflow-cpu\Lib\site-packages 里面的内容与spyder直接覆盖合并,似乎这样也行,但我不建议这么做了。 其实在当前环境下(tensorflow-cpu)直接命令 Spyder 就可以成功启动spyder了。
启动后在Spyder中输入如下代码:
import tensorflow as tf
hello = tf.constant("Hello!TensorFlow")
sess = tf.Session()
print(sess.run(hello))
参考文章:
http://blog.csdn.net/lwplwf/article/details/54896088
http://blog.csdn.net/lijihw_1022/article/details/72731030
http://blog.csdn.net/lijihw_1022/article/details/72731030