TensorFlow安装:Windows上的“Native pip”

时间:2017-02-24 15:54:19

标签: python windows tensorflow

我拼命想在Windows 10机器(64位)上安装TensorFlow(和Keras)。我能够在Ubuntu Linux上安装Keras,但现在需要在Windows上运行。

我按照官方说明操作:https://www.tensorflow.org/install/install_windows 特别是“使用原生点”安装的那些。

首先,我从python.org下载了python 3.5。

D:\>python --version
Python 3.5.3

然后我跑pip3 install --upgrade tensorflow-gpu。 CUDA 8,cuDNN 5.1和所有其他要求都得到满足。

现在,如果我问一些细节:

D:\>pip3 show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.0.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: d:\python\lib\site-packages
Requires: wheel, numpy, protobuf, six

如果我测试它:

D:\>python
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> 

由于import,我没有错误消息。但那时:

>>> hello = tf.constant('Hello, TensorFlow!')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'constant'

我已经在StackOverflow上阅读了其他问题的答案,但找不到任何指向解决方案的指针。在某些情况下,人们在使用名为tensorflow.py的文件时遇到了同样的问题,但是我检查了这个并且找不到任何带有该文件名的脚本。

在Linux下这很容易,我觉得在Windows上这不是很难,但我错了。

我按照指示说明......我错过了什么?

评论的答案。

dir(tf)

注意我没有运行脚本但是使用了提示 - 如果我使用脚本,则没有任何更改。

d:\>python
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>> dir(tf)
['_LazyContribLoader', '__builtins__', '__cached__', '__doc__', '__file__',
'__loader__', '__name__', '__package__', '__path__', '__spec__', 
'absolute_import', 'contrib', 'division', 'print_function', 'python']

>>> tf.__file__
'D:\\python\\lib\\site-packages\\tensorflow\\__init__.py'

更新

我使用以下命令卸载了tensorflow:

d:\pip3 uninstall tensorflow-gpu
[...]
d:\python\lib\site-packages\tensorflow_gpu-1.0.0.dist-info\wheel
d:\python\scripts\tensorboard.exe
Proceed (y/n)? y
Successfully uninstalled tensorflow-gpu-1.0.0

现在,如果我导入tensorflow,则会收到错误消息:

D:\>python
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [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>
  ImportError: No module named 'tensorflow'
>>>

因此,此行为应排除另一个tensorflow文件导致我所描述的错误的事实。我是对的吗?

接下来,我再次安装了模块tensorflow-gpu

D:\>pip3 install --upgrade tensorflow-gpu
Collecting tensorflow-gpu
  Using cached tensorflow_gpu-1.0.0-cp35-cp35m-win_amd64.whl
Requirement already up-to-date: six>=1.10.0 in d:\python\lib\site-packages (from tensorflow-gpu)
Requirement already up-to-date: protobuf>=3.1.0 in d:\python\lib\site-packages (from tensorflow-gpu)
Requirement already up-to-date: numpy>=1.11.0 in d:\python\lib\site-packages (from tensorflow-gpu)
Requirement already up-to-date: wheel>=0.26 in d:\python\lib\site-packages (from tensorflow-gpu)
Requirement already up-to-date: setuptools in d:\python\lib\site-packages (from protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: appdirs>=1.4.0 in d:\python\lib\site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: packaging>=16.8 in d:\python\lib\site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: pyparsing in d:\python\lib\site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-gpu)
Installing collected packages: tensorflow-gpu
Successfully installed tensorflow-gpu-1.0.0

D:\>python
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] successfully opened CUDA library cublas64_80.dll locally
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:126] Couldn't open CUDA library cudnn64_5.dll
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\cuda\cuda_dnn.cc:3517] Unable to load cuDNN DSO
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] successfully opened CUDA library cufft64_80.dll locally
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] successfully opened CUDA library nvcuda.dll locally
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] successfully opened CUDA library curand64_80.dll locally
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:885] Found device 0 with properties:
name: GeForce GTX 970
major: 5 minor: 2 memoryClockRate (GHz) 1.228
pciBusID 0000:01:00.0
Total memory: 4.00GiB
Free memory: 3.31GiB
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:906] DMA: 0
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:916] 0:   Y
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 970, pci bus id: 0000:01:00.0)
>>> print(sess.run(hello))
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "BestSplits" device_type: "CPU"') for unknown op: BestSplits
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "CountExtremelyRandomStats" device_type: "CPU"') for unknown op: CountExtremelyRandomStats
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "FinishedNodes" device_type: "CPU"') for unknown op: FinishedNodes
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "GrowTree" device_type: "CPU"') for unknown op: GrowTree
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "ReinterpretStringToFloat" device_type: "CPU"') for unknown op: ReinterpretStringToFloat
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "SampleInputs" device_type: "CPU"') for unknown op: SampleInputs
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "ScatterAddNdim" device_type: "CPU"') for unknown op: ScatterAddNdim
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TopNInsert" device_type: "CPU"') for unknown op: TopNInsert
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TopNRemove" device_type: "CPU"') for unknown op: TopNRemove
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TreePredictions" device_type: "CPU"') for unknown op: TreePredictions
E c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "UpdateFertileSlots" device_type: "CPU"') for unknown op: UpdateFertileSlots
b'Hello, TensorFlow!'

所以,现在它似乎正在发挥作用。整个过程是:

  • 安装所需的软件和库
  • 从python.org安装python 3.5
  • 原生安装tensorflow-gpu(使用pip3
  • 卸载tensorflow-gpu
  • 安装tensorflow-gpu

可能是python专家可以理解发生了什么......

PS。昨天我尝试使用Anaconda安装它,但在尝试安装Keras所需的软件包时,后续步骤出现问题。在Linux上,我对Keras也没有任何问题。

3 个答案:

答案 0 :(得分:1)

解决方案是卸载并重新安装tensorflow-gpu。现在它似乎正在发挥作用。

找不到cuDNN,但至少运行测试脚本。

答案 1 :(得分:0)

这可能听起来很奇怪,但是你的任何文件夹或脚本名为tensorflow吗?

tensorflow/script.py

dir/tensorflow.py

尝试将其更改为tensorflow,然后重试。
如果这没有解决问题,请告诉我

这背后的推理以及为什么我要求查看dir(tf)的输出:

以下是导入时搜索模块的顺序:

  
      
  1. 包含输入脚本的目录(或未指定文件时的当前目录)。

  2.   
  3. PYTHONPATH(目录名列表,   使用与shell变量PATH相同的语法。

  4.   
  5. 依赖于安装的默认值。

  6.   

答案 2 :(得分:0)

我遇到了同样的问题。为了解决这个问题,我做了一个全新的python 3.5.2&amp; amp; tensorfow(pip3 install --upgrade tensorflow)。 然后我写了一个helloMundo.py,内容如下:

import tensorflow as tf
# Simple hello world using TensorFlow
# The value returned by the constructor represents the output
# of the Constant op.
hello = tf.constant('Hello, TensorFlow gr!')
# Start tf session
sess = tf.Session()
# Run the op
print(sess.run(hello))} 

我从python IDLE打开helloMundo.py,然后打开菜单Run - &gt;运行模块(或F5),它可以工作。

尝试将您的代码放在.py文件中。

此致 F. Kubha