【问题标题】:installing tensorflow in windows anaconda - and running using it using Spyder GUI在 windows anaconda 中安装 tensorflow - 并使用 Spyder GUI 运行它
【发布时间】:2017-12-26 18:02:22
【问题描述】:

我访问了the tensorflow page 并按照Installing with Anaconda 部分的说明进行操作。当我尝试验证我的安装时,出现以下错误

(C:\ProgramData\Anaconda3) C:\Users\nik>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:\ProgramData\Anaconda3) C:\Users\nik>activate tensorflow

(tensorflow) C:\Users\nik>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\nik>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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_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:

  1. 我想在输入命令后验证安装 - activate tensorflow 如上面第二个命令块所示?
  2. 为什么我收到多条指令后 命令sess = tf.Session() ?
  3. 我可以在 蜘蛛侠?如何?我在下面尝试过,但在 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'

【问题讨论】:

  • activate 不是 python 命令。这是一个shell脚本。要使用tensorflow,请在tensorflow 环境中使用python
  • 我还是不清楚。请再次解释我如何在 spyder gui 中使用 tensorflow
  • 您有多个anaconda 环境,其中两个名为roottensorflow。如果您知道安装 anaconda 的位置,则环境将位于 envs/ 子目录中,而您需要的 python 位于 envs/tensorflow/bin/python 中。 conda env list 将列出您的所有环境。
  • 目前还不清楚。我去了.conda 文件夹,我有一个名为enviroments 的文件,它有C:\Users\nik\AppData\Local\conda\conda\envs\tensorflow。我需要在这里添加一些东西吗?
  • 有了这些信息,你需要的python是C:\Users\nik\AppData\Local\conda\conda\envs\tensorflow\bin\python

标签: python windows tensorflow anaconda spyder


【解决方案1】:

Q1:是的,您需要激活虚拟环境才能导入 tensorflow,因为您已经在虚拟环境中安装了 tensorflow。

Q2:不知道为什么会有多条指令,但这是正常的,并且是内置在 tensorflow 中的。您可以通过启用 SIMD 指令自己构建 tensorflow 来避免这些问题。 https://www.youtube.com/watch?v=ghv5fbC287o

Q3:创建虚拟环境的第一步需要改变。使用以下命令 {conda create -n tensorflow python=3.5 anaconda} 创建虚拟环境。

您的 Q3 的详细答案如下:

  1. 使用“conda create -n tensorflow python=3.5 anaconda”创建 tensorflow 环境

  2. 创建虚拟环境后,输入命令“activate tensorflow”

  3. 现在使用“pip install tensorflow”(仅限 CPU)或 pip install tensorflow-gpu(用于 GPU)安装 tensorflow。

  4. 现在转到安装 anaconda 的文件夹。

  5. 如果 C:\ProgramData\Anaconda3 是 Anaconda 根文件夹,则转到“C:\ProgramData\Anaconda3\envs\test\Scripts”并打开 spyder.exe。你应该可以在这个环境下成功导入 tensorflow。

【讨论】:

  • 我已经使用我的问题中提到的链接安装了 tensorflow。我输入了命令conda create -n tensorflow python=3.5 ,然后输入了pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl。我需要重复步骤 1,2 和 3 吗?我会在哪里运行 1 和 2 - 在 anaconda 提示符下?
  • 我在 anaconda promopt 中尝试了conda create -n tensorflow python=3.5 anaconda 并收到了消息CondaValueError: prefix already exists: C:\Users\nikh\AppData\Local\conda\conda\envs\tensorflow。我继续输入activate tensorflow,然后输入python,然后`import tensorflow as tf`,一切都在anaconda提示符下顺利进行。但我仍然无法在 spyder 中运行 tensorflow
  • 在创建同名之前,需要先删除之前的conda环境。您收到错误是因为您已经有一个名为 tensorflow 的环境。您可以通过 conda remove --all tensorflow 删除环境,如果您不想删除环境,则创建一个具有不同名称的新环境,conda create -n tensorflowspyder python=3.5 anaconda。
  • 在执行完步骤 1 到 5 之后,我能够从 spyder 运行 tensorflow。我使用命令 pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensor‌​flow-1.2.1-cp35-cp35‌​m-win_amd64.whl 安装了 tensorflow。请将您的 cmets 添加到答案中,以便我可以奖励您的赏金。可以回答以下问题吗? 1)您给出的创建语句与我使用的语句有什么区别。为什么你的陈述有效 2)你的 pip install 命令和我用过的有什么区别
  • 3) 要在 spyder 中使用 tensorflow,我是否必须始终使用显示 spyder (tensorflowspyder) 的快捷方式 4) 我应该如何关闭 python/spyder?从 anaconda 提示符停用 tensorflowspyder 后,我应该注销吗?
【解决方案2】:

您应该从命令提示符激活您的虚拟环境。激活后,您应该运行命令spyder这将从您的虚拟环境中打开 spyder gui

【讨论】:

    【解决方案3】:

    问题是您的 tensorflow 安装在 conda 环境中。因此,首先以管理员身份打开 conda 提示符,然后通过键入“activate tensorflow”激活 tensorflow 环境,然后通过键入 spyder 打开你的 spyder gui。主要是解决问题。

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 2016-09-04
      • 1970-01-01
      • 2020-09-08
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-11-19
      • 2018-08-11
      相关资源
      最近更新 更多