I wrote a tutorial on installing TensorFlow under ubuntu. At that time, TensorFlow did not officially support Windows systems. Although it could be installed by other methods, it was not native after all, and the installation process was cumbersome and error-prone. The good news is that Google officially announced in the developer blog on November 29th that the new version (0.12) will add support for Windows . I knew it on November 30th, and I installed it immediately. The installation process is very simple. However, there are some that need to be adjusted manually.
renew
Here I will list updates to this article.
- March 1, 2017: The cuDNN version was upgraded from 5.0 to 5.1, and the download addresses of cuda and cudnn were updated.
- March 20, 2017: Mark item 5 of Pre-Installation Preparation Make sure you have VS2015 or 2013 or 2010 installed. for doubt. This is what I saw on the TensorFlow official website before, but now I can't find it after searching. If some students successfully installed TensorFlow without installing VS, please explain in the comment area below, and I will mark this request as deleted. Thanks.
- March 26, 2017: Updated TensorFlow installation commands.
- April 18, 2017: Preparations before installation The fifth item is marked as deleted. After another test, I found that VS support is not needed. Add solutions
Cannot remove entries from nonexistent file
to . - July 20, 2017: Added problem
ImportError: DLL load failed: 找不到指定的模块。
, andImportError: No module named '_pywrap_tensorflow_internal'
time` solution.ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal
- July 31, 2017: Updated note about Python version, TensorFlow supports Python 3.6 on Windows from 1.2. Thanks to @Vince_Ace in the comment section for the info.
Preparations before installation
TensorFlow has two versions: CPU version and GPU version. The GPU version requires CUDA and cuDNN support, but the CPU version does not. If you want to install the GPU version, please make sure your graphics card supports CUDA . I installed the GPU version, using pip installation method , so take the GPU installation as an example, the CPU version does not need to install CUDA and cuDNN.
- Make sure your graphics card supports CUDA here .
- Make sure your Python version is 3.5 64-bit and above. (TensorFlow supports Python 3.6 from 1.2, which was not officially supported before )
- Make sure you have a stable internet connection.
- Make sure your pip version >= 8.1.
pip -V
Check the currentpip
version with andpython -m pip install -U pip
upgradepip
. - Make sure you have VS2015 or 2013 or 2010 installed. This article is not required, delete it.
In addition, it is recommended to install Anaconda, because it integrates many libraries necessary for scientific computing, which can avoid many dependency problems, and the installation tutorial can be found here .
If the above conditions are met, congratulations, you can start downloading the installation packages of CUDA and cuDNN. Note that the version numbers are CUDA 8.0 and cuDNN 5.1 , which are officially recommended by Google. You can go to their respective official websites to download. I have already downloaded it into a compressed package and put it on Baidu Cloud. You can download it from here , the password is 5aoc.
Install TensorFlow
Since the Googlers have made TensorFlow into a pip installation package, you can now install TensorFlow in the normal way, just enter the command line and execute the following simple statement:
# GPU版本
pip3 install --upgrade tensorflow-gpu
# CPU版本
pip3 install --upgrade tensorflow
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
Then start the installation, the speed depends on the speed of the network.
After installing the network, if you try to use Python , import tensorflow
it will tell you that CUDA and cuDNN are not found, so the next step is to install these two things.
Install CUDA 8.0
This is also very simple. After downloading the compressed package I gave above, unzip it and get two files. The exe file is the CUDA8 installer. Just double-click to execute it, just like installing other normal software. The installation process The screen might flicker, that's ok, and it takes a little long to install.
After the installation is complete, the system variables will be automatically added for you, so don't worry about it.
Test whether the installation is successful, enter the command line nvcc -V
, and see the version information, which means the installation is successful.
Install cuDNN 5.1
In fact, this is a compressed package, just unzip it and put it in any directory, and then add the directory you put it to the Path
environment variable.
For example mine is:
Path
Environment variables:
According to the official installation steps, this has actually been completed here, but after my installation, I found that if you import tensorflow
do it still cannot find the cuDNN file, that is to say, the line in the purple box below is a failure:
Then I found that someone submitted the same issue on GitHub, you can take a look here , and then solve this problem in this way: copy the following files to the corresponding location,
C:\cuda\bin\cudnn64_5.dll
—>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
C:\cuda\include\cudnn.h
—>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
C:\cuda\lib\x64\cudnn.lib
—>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64
In addition, there is another way is to C:\cuda\bin
also add to Path
the environment variable, which is also feasible after testing.
If you have installed cuDNN 5.0, you can refer to here for how to upgrade cuDNN .
Then import tensorflow
it should work again.
test
Test it out with a simple matrix multiplication,
import tensorflow as tf
a = tf.random_normal((100, 100))
b = tf.random_normal((100, 500))
c = tf.matmul(a, b)
sess = tf.InteractiveSession()
sess.run(c)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
If you can't see it clearly, you can right click to open the picture in a new tab to view a larger picture
You can see that my graphics card has been recognized (don't complain about my scumbag graphics card, it's a poor one).
Finally, I can play happily with TensorFlow on Windows~~~
Possible problems with installation
Cannot remove entries from nonexistent file
If Cannot remove entries from nonexistent file c:\users\li\anaconda3\lib\site-packages\easy-install.pth
similar , you can refer to Cannot remove entries from nonexistent #622 and osx 10.11 installation issues #135 , which describe many solutions. Here I introduce a method: execute pip3 install --upgrade tensorflow-gpu
before pip install --upgrade --ignore-installed setuptools
.
ImportError: DLL load failed: 找不到指定的模块。
andImportError: No module named '_pywrap_tensorflow_internal'
Right click to open the image in a new tab to view a larger image
Right click to open the image in a new tab to view a larger image
Right click to open the image in a new tab to view a larger image
import tensorflow
If these two problems appear at the same time , it is very likely that there is a problem with your cuda and cudnn version. For example, your cuda version is 8.0.60
, and the correct one is 8.0.44
to reinstall the correct version (provided in the article). . Refer to On Windows, running “import tensorflow” generates No module named “_pywrap_tensorflow” error . Thanks to @qq_27690673 for the information.
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
Right click to open the image in a new tab to view a larger image
import tensorflow
If this problem occurs when , then you may have entered the python interpreter in the source code directory of tensorflow. Just leave this directory and re-enter the python interpreter.