Install TensorFlow with Anaconda under Win10

Permanent update address: https://my.oschina.net/bysu/blog/1632523

1. Download https://repo.continuum.io/archive/Anaconda3-5.1.0-Windows-x86_64.exe

Anaconda installed successfully.

If the start menu and desktop do not have shortcut keys, you can find related programs in Scripts in the installation directory.

If you need to start this, then double-click to run anaconda-navigator.exe .

If you need to open Anaconda Prompt , this command window, you need to open the cmd window first (if you don't know how to open cmd, please search the engine yourself), then drag the activate.bat file into the opened cmd window with the mouse, and release the mouse , use the cd command to switch to the directory where activate.bat is located. The steps are shown in the figure below: 

 

If the start menu and desktop have shortcut keys, then ignore the above operations.

Next, you need to set up the Anaconda warehouse mirror, because the default connection is to the foreign mirror address, and the download speed is relatively slow. We change the mirror address to the Tsinghua University open source software mirror station, open Anaconda Prompt, and enter:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

2. Install TensorFlow

Continue to enter in the Anaconda Prompt window:

conda create -n tensorflow python=3.5

Press Enter.

Indicates the creation of a TensorFlow-dependent environment. TensorFlow does not currently support Python3.6. Here we use Python3.5.

Continue to see the console output:

Fetching package metadata ...............
Solving package specifications: .

Package plan for installation in environment D:\Program Files\anaconda\envs\tensorflow:

The following NEW packages will be INSTALLED:

    pip:            9.0.1-py35_1  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    python:         3.5.3-0       https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    setuptools:     27.2.0-py35_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    vs2015_runtime: 14.0.25123-0  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    wheel:          0.29.0-py35_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

Proceed ([y]/n)? y

Prompt us which dependent software to install, enter 'y' and press Enter.

The console continues to output:

python-3.5.3-0 100% |###############################| Time: 0:00:42 754.91 kB/s
setuptools-27. 100% |###############################| Time: 0:00:00   1.92 MB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:00   2.68 MB/s
pip-9.0.1-py35 100% |###############################| Time: 0:00:00   2.31 MB/s
#
# To activate this environment, use:
# > activate tensorflow
#
# To deactivate this environment, use:
# > deactivate tensorflow
#
# * for power-users using bash, you must source
#

Start downloading and installing dependent software. I use the mirror warehouse of Tsinghua University here, so the download speed is very fast.

3. Start the tensorflow environment in Anaconda Prompt:

activate tensorflow

Install the cpu version of TensorFlow

pip install --upgrade --ignore-installed tensorflow

 Note: The installation method of the GPU version is not introduced here. The GPU version needs to install cuda8+cudnn5. If you need it, please search other blog posts. This way the tensorflow cpu version is installed.

4. Test tensorflow 
Start the tensorflow environment in Anaconda Prompt and enter the python environment. 

Start the tensorflow environment

activate tensorflow

When not using tensorflow, close the tensorflow environment, the command is:deactivate

Start the tensorflow environment in Anaconda Prompt and enter the python environment.

The test code is as follows:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

 

In order to use tensorflow in ipython and Spyder, we need to install these two plugins in the tensorflow environment. But I don't like ipython, so I only install Spyder , and installing ipython is the same as Spyder.

Open Anaconda Navigator, select All , find Spyder and install it, the author has already installed it here, see the picture below. 

After installing the plugin, we need to test it.

Start the tensorflow environment in Anaconda Prompt and run Spyderit. After a while, the Spyder IDE will be launched, and the import tensorflow will also succeed.

After installing it, if you are too lazy to run anaconda, you can use a batch to run sypder directly. as follows:

@echo off

cd "D:\bysu\Application\anaconda3\envs\qxc\Scripts\"
call activate.bat
spyder.exe

However, you need to pay attention to the path of the environment, which is the cd + path in the batch script. You can change this path.

Reference: http://blog.csdn.net/u010858605/article/details/64128466

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325077524&siteId=291194637