在Windows anaconda中安装tensorflow - 并使用Spyder GUI运行它
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Windows anaconda中安装tensorflow - 并使用Spyder GUI运行它相关的知识,希望对你有一定的参考价值。
我访问了the tensorflow page并遵循了Installing with Anaconda
部分的指示。当我尝试验证我的安装时,我遇到了以下错误
(C:ProgramDataAnaconda3) C:Users
ik>python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [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 "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>> hello = tf.constant('Hello, TensorFlow!')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> exit
Use exit() or Ctrl-Z plus Return to exit
>>> exit()
然后我试过了
(C:ProgramDataAnaconda3) C:Users
ik>activate tensorflow
(tensorflow) C:Users
ik>pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
Collecting tensorflow==1.2.1 from https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
Using cached https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
Collecting bleach==1.5.0 (from tensorflow==1.2.1)
Using cached bleach-1.5.0-py2.py3-none-any.whl
Collecting html5lib==0.9999999 (from tensorflow==1.2.1)
Collecting backports.weakref==1.0rc1 (from tensorflow==1.2.1)
Using cached backports.weakref-1.0rc1-py3-none-any.whl
Collecting werkzeug>=0.11.10 (from tensorflow==1.2.1)
Using cached Werkzeug-0.12.2-py2.py3-none-any.whl
Collecting markdown>=2.6.8 (from tensorflow==1.2.1)
Collecting protobuf>=3.2.0 (from tensorflow==1.2.1)
Collecting numpy>=1.11.0 (from tensorflow==1.2.1)
Using cached numpy-1.13.1-cp35-none-win_amd64.whl
Collecting six>=1.10.0 (from tensorflow==1.2.1)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting wheel>=0.26 (from tensorflow==1.2.1)
Using cached wheel-0.29.0-py2.py3-none-any.whl
Collecting setuptools (from protobuf>=3.2.0->tensorflow==1.2.1)
Using cached setuptools-36.2.0-py2.py3-none-any.whl
Installing collected packages: six, html5lib, bleach, backports.weakref, werkzeug, markdown, setuptools, protobuf, numpy, wheel, tensorflow
Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 html5lib-0.9999999 markdown-2.6.8 numpy-1.13.1 protobuf-3.3.0 setuptools-36.2.0 six-1.10.0 tensorflow-1.2.1 werkzeug-0.12.2 wheel-0.29.0
(tensorflow) C:Users
ik>python
Python 3.5.3 |Continuum Analytics, Inc.| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-07-20 12:20:26.177654: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.178276: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.178687: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.179189: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.179713: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.180250: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.180687: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-20 12:20:26.181092: W c: f_jenkinshomeworkspace
elease-winmwindowspy35 ensorflowcoreplatformcpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
我的问题如下 - 我的主要问题是问题3:
- 我想在键入命令 -
activate tensorflow
之后验证安装,如上面的第二个命令块所示? - 为什么我在命令
sess = tf.Session()
后得到多个指令? - 我可以在SPYDER gui中使用tensorflow吗?怎么样?我试过下面但是在SPYDER gui,但没有取得任何成功:( 激活张量流
文件“”,第1行
activate tensorflow
^
SyntaxError: invalid syntax
import tensorflow as tf
Traceback (most recent call last):
File "<ipython-input-2-41389fad42b5>", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
Q1:是的,您需要激活虚拟环境以导入tensorflow,因为您已在虚拟环境中安装了tensorflow。
Q2:不确定为什么有多个指令但是这是正常的并且内置在tensorflow中。您可以通过在启用SIMD指令的情况下自行构建张量流来避免这些问题。 https://www.youtube.com/watch?v=ghv5fbC287o
问题3:您需要在创建虚拟环境时更改第一步。使用以下命令创建虚拟环境{conda create -n tensorflow python = 3.5 anaconda}。
Q3的详细答案如下:
- 使用“conda create -n tensorflow python = 3.5 anaconda”创建tensorflow环境
- 创建虚拟环境后,输入命令“activate tensorflow”
- 现在使用“pip install tensorflow”(仅限CPU)或pip install tensorflow-gpu(用于GPU)安装tensorflow。
- 现在转到安装anaconda的文件夹。
- 如果C: ProgramData Anaconda3是Anaconda根文件夹,则转到“C: ProgramData Anaconda3 envs test Scripts”并打开spyder.exe。您应该能够在此环境中成功导入tensorflow。
您应该从命令提示符处激活虚拟环境。一旦激活,你应该运行命令spyder
which将打开你的虚拟环境中的spyder gui
问题是你的张量流安装在conda环境中。因此,首先以管理员身份打开conda提示符,然后键入“activate tensorflow”激活tensorflow环境,然后键入spyder打开你的spyder gui。它主要解决问题。
以上是关于在Windows anaconda中安装tensorflow - 并使用Spyder GUI运行它的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Windows 上的 Anaconda Python 中安装 Keras 和 Theano?
在 windows anaconda 中安装 tensorflow - 并使用 Spyder GUI 运行它
在Windows anaconda中安装tensorflow - 并使用Spyder GUI运行它