【深度學習】Anaconda3與TensorFlow安裝教程


環境介紹

  1. 操作系統:win10 64位
  2. Anaconda3版本:5.2.0
  3. Python版本:3.6.2
  4. TensorFlow版本:1.14.0

安裝過程

一、安裝Anaconda3

鏈接:https://repo.continuum.io/archive/Anaconda3-5.2.0-Windows-x86_64.exe
安裝Anaconda3

二、更改pip安裝源(新建pip.ini文件)

在這裏插入圖片描述

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

三、更改conda安裝源(Anaconda Prompt命令)

在這裏插入圖片描述

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

四、創建一個python3.6的環境

conda create -n tensorflow python=3.6
(base) C:\WINDOWS\system32>conda create -n tensorflow python=3.6
Solving environment: done

==> WARNING: A newer version of conda exists. <==
  current version: 4.5.4
  latest version: 4.8.3

Please update conda by running
    $ conda update -n base conda

## Package Plan ##
  environment location: C:\ProgramData\Anaconda3\envs\tensorflow
  added / updated specs:
   - python=3.6

The following packages will be downloaded:
    package                    |            build
    ---------------------------|-----------------
    pip-9.0.1                  |           py36_1         1.7 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    vs2015_runtime-14.0.25420  |                0         2.0 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    certifi-2016.2.28          |           py36_0         214 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    vc-14                      |                0          703 B  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    setuptools-36.4.0          |           py36_1         534 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    python-3.6.2               |                0        31.5 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    wincertstore-0.2           |           py36_0          14 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    wheel-0.29.0               |           py36_0         129 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    ------------------------------------------------------------
                                           Total:        36.0 MB
                                           
The following NEW packages will be INSTALLED:
    certifi:        2016.2.28-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    pip:            9.0.1-py36_1     https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    python:         3.6.2-0          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    setuptools:     36.4.0-py36_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    vc:             14-0             https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    vs2015_runtime: 14.0.25420-0     https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    wheel:          0.29.0-py36_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    wincertstore:   0.2-py36_0       https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    
Proceed ([y]/n)? y

Downloading and Extracting Packages
pip-9.0.1            |  1.7 MB | ############################################################################## | 100%
vs2015_runtime-14.0. |  2.0 MB | ############################################################################## | 100%
certifi-2016.2.28    |  214 KB | ############################################################################## | 100%
vc-14                |   703 B | ############################################################################## | 100%
setuptools-36.4.0    |  534 KB | ############################################################################## | 100%
python-3.6.2         | 31.5 MB | ############################################################################## | 100%
wincertstore-0.2     |   14 KB | ############################################################################## | 100%
wheel-0.29.0         |  129 KB | ############################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

#
# To activate this environment, use
#
#     $ conda activate tensorflow
#
# To deactivate an active environment, use
#
#     $ conda deactivate

五、安裝cpu版本的TensorFlow

activate tensorflow
pip install --upgrade --ignore-installed tensorflow==1.14
(tensorflow) C:\WINDOWS\system32>pip install --upgrade --ignore-installed tensorflow==1.14
Collecting tensorflow==1.14
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/4a/5c86ed8b245aa48f9f819b13a0a9039e9126ba19fdd0c7e0b8026c12315a/tensorflow-1.14.0-cp36-cp36m-win_amd64.whl (68.3MB)
    100% |████████████████████████████████| 68.3MB 629kB/s
Collecting grpcio>=1.8.6 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/8e/f01dd2b7e845fe8bf6c93dc240e4a7a839e85a0f1a9038c86c3aebbdc658/grpcio-1.29.0-cp36-cp36m-win_amd64.whl (2.4MB)
    100% |████████████████████████████████| 2.4MB 6.6MB/s
Collecting tensorboard<1.15.0,>=1.14.0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/91/2d/2ed263449a078cd9c8a9ba50ebd50123adf1f8cfbea1492f9084169b89d9/tensorboard-1.14.0-py3-none-any.whl (3.1MB)
    100% |████████████████████████████████| 3.2MB ...
Collecting keras-preprocessing>=1.0.5 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/79/4c/7c3275a01e12ef9368a892926ab932b33bb13d55794881e3573482b378a7/Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42kB)
    100% |████████████████████████████████| 51kB 2.5MB/s
Collecting gast>=0.2.0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/84/759f5dd23fec8ba71952d97bcc7e2c9d7d63bdc582421f3cd4be845f0c98/gast-0.3.3-py2.py3-none-any.whl
Collecting absl-py>=0.7.0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1a/53/9243c600e047bd4c3df9e69cfabc1e8004a82cac2e0c484580a78a94ba2a/absl-py-0.9.0.tar.gz (104kB)
    100% |████████████████████████████████| 112kB ...
Collecting tensorflow-estimator<1.15.0rc0,>=1.14.0rc0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/3c/d5/21860a5b11caf0678fbc8319341b0ae21a07156911132e0e71bffed0510d/tensorflow_estimator-1.14.0-py2.py3-none-any.whl (488kB)
    100% |████████████████████████████████| 491kB 109kB/s
Collecting wrapt>=1.11.1 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/82/f7/e43cefbe88c5fd371f4cf0cf5eb3feccd07515af9fd6cf7dbf1d1793a797/wrapt-1.12.1.tar.gz
Collecting astor>=0.6.0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/88/97eef84f48fa04fbd6750e62dcceafba6c63c81b7ac1420856c8dcc0a3f9/astor-0.8.1-py2.py3-none-any.whl
Collecting wheel>=0.26 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8c/23/848298cccf8e40f5bbb59009b32848a4c38f4e7f3364297ab3c3e2e2cd14/wheel-0.34.2-py2.py3-none-any.whl
Collecting numpy<2.0,>=1.14.5 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4e/a0/7c78c8a2bb3f93eda58c4397936b669952051eef355e9e87a61ac29609e1/numpy-1.19.0-cp36-cp36m-win_amd64.whl (13.0MB)
    100% |████████████████████████████████| 13.0MB 10.1MB/s
Collecting keras-applications>=1.0.6 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/71/e3/19762fdfc62877ae9102edf6342d71b28fbfd9dea3d2f96a882ce099b03f/Keras_Applications-1.0.8-py3-none-any.whl (50kB)
    100% |████████████████████████████████| 51kB 6.3MB/s
Collecting protobuf>=3.6.1 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1a/59/3e630ae8a78d7faafc1697a3b3f7f70384c720895f4ba0a530d296954c1a/protobuf-3.12.2-cp36-cp36m-win_amd64.whl (1.1MB)
    100% |████████████████████████████████| 1.1MB 6.6MB/s
Collecting six>=1.10.0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Collecting termcolor>=1.1.0 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Collecting google-pasta>=0.1.6 (from tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/de/c648ef6835192e6e2cc03f40b19eeda4382c49b5bafb43d88b931c4c74ac/google_pasta-0.2.0-py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 1.0MB/s
Collecting markdown>=2.6.8 (from tensorboard<1.15.0,>=1.14.0->tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/63/eaec2bd025ab48c754b55e8819af0f6a69e2b1e187611dd40cbbe101ee7f/Markdown-3.2.2-py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 509kB/s
Collecting setuptools>=41.0.0 (from tensorboard<1.15.0,>=1.14.0->tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e9/93/4860cebd5ad3ff2664ad3c966490ccb46e3b88458b2095145bca11727ca4/setuptools-47.3.1-py3-none-any.whl (582kB)
    100% |████████████████████████████████| 583kB 2.0MB/s
Collecting werkzeug>=0.11.15 (from tensorboard<1.15.0,>=1.14.0->tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298kB)
    100% |████████████████████████████████| 307kB 635kB/s
Collecting h5py (from keras-applications>=1.0.6->tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0b/fa/bee65d2dbdbd3611702aafd128139c53c90a1285f169ba5467aab252e27a/h5py-2.10.0-cp36-cp36m-win_amd64.whl (2.4MB)
    100% |████████████████████████████████| 2.4MB 473kB/s
Collecting importlib-metadata; python_version < "3.8" (from markdown>=2.6.8->tensorboard<1.15.0,>=1.14.0->tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/98/13/a1d703ec396ade42c1d33df0e1cb691a28b7c08b336a5683912c87e04cd7/importlib_metadata-1.6.1-py2.py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->markdown>=2.6.8->tensorboard<1.15.0,>=1.14.0->tensorflow==1.14)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b2/34/bfcb43cc0ba81f527bc4f40ef41ba2ff4080e047acb0586b56b3d017ace4/zipp-3.1.0-py3-none-any.whl
Building wheels for collected packages: absl-py, wrapt, termcolor
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: C:\Users\wangw\AppData\Local\pip\Cache\wheels\55\fd\b5\4db4cce08516c3aaa68ee4c843439f45c7fcf177320ba63d9f
  Running setup.py bdist_wheel for wrapt ... done
  Stored in directory: C:\Users\wangw\AppData\Local\pip\Cache\wheels\68\e3\d7\4b6eee6f5d547bdfd97ba406128db66c5654dfb831fda163a2
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: C:\Users\wangw\AppData\Local\pip\Cache\wheels\e3\d8\fc\50ab6e66e3dead21d5afff006dc5298913a3064be2b1105359
Successfully built absl-py wrapt termcolor
Installing collected packages: six, grpcio, numpy, zipp, importlib-metadata, markdown, setuptools, wheel, absl-py, protobuf, werkzeug, tensorboard, keras-preprocessing, gast, tensorflow-estimator, wrapt, astor, h5py, keras-applications, termcolor, google-pasta, tensorflow
Successfully installed absl-py-0.9.0 astor-0.8.1 gast-0.3.3 google-pasta-0.2.0 grpcio-1.29.0 h5py-2.10.0 importlib-metadata-1.6.1 keras-applications-1.0.8 keras-preprocessing-1.1.2 markdown-3.2.2 numpy-1.19.0 protobuf-3.12.2 setuptools-47.3.1 six-1.15.0 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 werkzeug-1.0.1 wheel-0.34.2 wrapt-1.12.1 zipp-3.1.0

六、Anaconda Prompt測試

import tensorflow as tf
hello=tf.constant('Hello,TensorFlow!')
sess=tf.Session()
print(sess.run(hello))
sess.close()
(tensorflow) C:\WINDOWS\system32>python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> hello=tf.constant('Hello,TensorFlow!')
>>> sess=tf.Session()
2020-06-22 14:42:54.389355: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
>>> print(sess.run(hello))
b'Hello,TensorFlow!'
>>> sess.close()

七、配置Jupyter

配置Jupyter TensorFlow

八、Jupyter測試

在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章