在Win10上是用Anaconda搭建TensorFlow开发环境

时间:2022-05-06
本文章向大家介绍在Win10上是用Anaconda搭建TensorFlow开发环境,主要内容包括2.2 在Windows 10上搭建TensorFlow开发环境、2.2.1 安装TensorFlow、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

以下内容原本是作为毕业设计的一部分的,因此绝对认真和详细,由于内容过多所以被删减了,就当福利送给大家了。

2.2 在Windows 10上搭建TensorFlow开发环境

2.2.1 安装Anaconda5.0.1

在Windows下的安装十分简单,不需要很复杂的步骤。

https://www.anaconda.com/download/#windows 在Anaconda官网上下载相应版本的安装包,这篇论文选择的是”64-bit Graphical(515MB)”。

下载完成后直接运行。

选择可以使用Anaconda的用户,这里选择了Just Me,即当前登录的用户。

选择安装路径,这里选择了默认安装路径,你也可以选择其他路径。

第一个选项建议勾选,如果你不是第一次安装Anaconda,记得将之前的环境变量删除。 第二个选项默认勾选,如果你的电脑上安装有官方版的Python包或者其他发行版的包,将会被Anaconda覆盖掉。

安装成功,Window PowerShell或者CMD里输入python,会看到如下结果:

2.2.1 安装TensorFlow

在开始菜单中找到Anaconda Prompt并打开:

#创建一个虚拟环境
(C:UsershongzeAppDataLocalContinuumanaconda3) C:Usershongze>conda create -n tensorflow python=3.6
Fetching package metadata .............
Solving package specifications: .

Package plan for installation in environment C:UsershongzeAppDataLocalContinuumanaconda3envstensorflow:

The following NEW packages will be INSTALLED:

    certifi:        2017.11.5-py36hb8ac631_0
    pip:            9.0.1-py36h226ae91_4
    python:         3.6.4-h6538335_0
    setuptools:     38.4.0-py36_0
    vc:             14-h0510ff6_3
    vs2015_runtime: 14.0.25123-3
    wheel:          0.30.0-py36h6c3ec14_1
    wincertstore:   0.2-py36h7fe50ca_0

Proceed ([y]/n)? y

vs2015_runtime 100% |###############################| Time: 0:00:02 961.77 kB/s
vc-14-h0510ff6 100% |###############################| Time: 0:00:00 597.58 kB/s
python-3.6.4-h 100% |###############################| Time: 0:00:05   4.13 MB/s
certifi-2017.1 100% |###############################| Time: 0:00:00   6.32 MB/s
setuptools-38. 100% |###############################| Time: 0:00:00   8.99 MB/s
wheel-0.30.0-p 100% |###############################| Time: 0:00:00   4.69 MB/s
pip-9.0.1-py36 100% |###############################| Time: 0:00:00   7.68 MB/s
#
# To activate this environment, use:
# > activate tensorflow
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
#激活虚拟环境
(C:UsershongzeAppDataLocalContinuumanaconda3) C:Usershongze>activate tensorflow
#安装tensorflow
(tensorflow) C:Usershongze>pip install tensorflow
Collecting tensorflow
  Downloading tensorflow-1.4.0-cp36-cp36m-win_amd64.whl (28.3MB)
    100% |████████████████████████████████| 28.3MB 632kB/s
Collecting tensorflow-tensorboard<0.5.0,>=0.4.0rc1 (from tensorflow)
  Downloading tensorflow_tensorboard-0.4.0-py3-none-any.whl (1.7MB)
    100% |████████████████████████████████| 1.7MB 1.8MB/s
Collecting six>=1.10.0 (from tensorflow)
  Downloading six-1.11.0-py2.py3-none-any.whl
Collecting enum34>=1.1.6 (from tensorflow)
  Downloading enum34-1.1.6-py3-none-any.whl
Requirement already satisfied: wheel>=0.26 in c:usershongzeappdatalocalcontinuumanaconda3envstensorflowlibsite-packages (from tensorflow)
Collecting protobuf>=3.3.0 (from tensorflow)
  Downloading protobuf-3.5.1-py2.py3-none-any.whl (388kB)
    100% |████████████████████████████████| 389kB 1.4MB/s
Collecting numpy>=1.12.1 (from tensorflow)
  Downloading numpy-1.14.0-cp36-none-win_amd64.whl (13.4MB)
    100% |████████████████████████████████| 13.4MB 1.2MB/s
Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
    100% |████████████████████████████████| 327kB 1.9MB/s
Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading bleach-1.5.0-py2.py3-none-any.whl
Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading Markdown-2.6.11-py2.py3-none-any.whl (78kB)
    100% |████████████████████████████████| 81kB 1.5MB/s
Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading html5lib-0.9999999.tar.gz (889kB)
    100% |████████████████████████████████| 890kB 2.0MB/s
Requirement already satisfied: setuptools in c:usershongzeappdatalocalcontinuumanaconda3envstensorflowlibsite-packages (from protobuf>=3.3.0->tensorflow)
Building wheels for collected packages: html5lib
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: C:UsershongzeAppDataLocalpipCachewheels6f856c56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
Successfully built html5lib
Installing collected packages: werkzeug, six, html5lib, bleach, protobuf, markdown, numpy, tensorflow-tensorboard, enum34, tensorflow

Successfully installed bleach-1.5.0 enum34-1.1.6 html5lib-0.9999999 markdown-2.6.11 numpy-1.14.0 protobuf-3.5.1 six-1.11.0 tensorflow-1.4.0 tensorflow-tensorboard-0.4.0 werkzeug-0.14.1

(tensorflow) C:Usershongze>python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 15 2018, 18:58:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hw = tf.consatant("Hello World")
>>> with tf.Session() as sess:
...     sess.run(hw)
...
2018-01-18 19:04:19.733504: I C:tf_jenkinshomeworkspacerel-winMwindowsPY36tensorflowcoreplatformcpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
b'Hello World'
>>>

安装成功,Warning表示tensorflow的二进制文件不会用AVX AVX2被编译,因为你的CPU不支持这些指令, 因为之后的实现是在Jupyter上做的,所以这个可以忽略。