Antonio Sesto Antonio Sesto -4 years ago 470
Python Question

TensorFlow installation: 'Native pip' on Windows

I am desperately trying to install TensorFlow (and Keras) on a Windows 10 machine (64bit). I was able to have a working Keras installation on a Ubuntu Linux, but now need to have it working on Windows.

I am following the official instructions here: https://www.tensorflow.org/install/install_windows
specifically those at "Installing with native pip".

First, I downloaded python 3.5 from python.org.

D:\>python --version
Python 3.5.3


Then I run
pip3 install --upgrade tensorflow-gpu
. CUDA 8, cuDNN 5.1 and all the other requirements are satisfied.

Now if I ask some details:

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


If I test it:

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 have no error messages as a consequence of the
import
. But then:

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


I have read the answers to other questions here on StackOverflow but could not find any pointer to a solution. In some cases, people had the same problem when using a file named
tensorflow.py
, but I checked this and could not find any script with that filename.

It was very easy under Linux and I thought it could not be this hard on Windows, but I was wrong.

I followed the instructions... what did I miss?




Answers to comments.



dir(tf)
?

Note I am not running a script but using the prompt - nothing changes if I use a script.

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'





Update



I uninstalled tensorflow with the following command:

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


Now if I import
tensorflow
, I receive an error:

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'
>>>


So this behaviour should exclude the fact that another
tensorflow
file was causing the error I described. Am I right?




Next, I installed the module
tensorflow-gpu
again:

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!'


So, now it seems to be working. The entire procedure was:


  • install required software and libraries

  • install
    python 3.5
    from python.org

  • install
    tensorflow-gpu
    natively (using
    pip3
    )

  • uninstall
    tensorflow-gpu

  • install
    tensorflow-gpu



May be a python expert can understand what happened...




PS. Yesterday I tried to install it using Anaconda, but had problems in subsequent steps when trying to install the Keras required packages. On Linux I did not have any problem with Keras either.

Answer Source

The solution was to uninstall and re-install tensorflow-gpu. Now it seems to be working.

It does not find cuDNN, but at least the test script runs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download