zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Win10上安装anaconda深度学习开发环境

安装学习win10开发 环境 深度 Anaconda
2023-09-11 14:15:47 时间

1.下载anaconda

点开下面的链接,下载版本Anaconda3-4.1.1-Windows-x86_64.exe

https://repo.anaconda.com/archive/

 2.安装anaconda

一路点击安装

  3.安装tensorflow

两种方式安装TF,第一种是通过命令来安装,在anaconda prompt下PIP安装:

下载非常的慢,一个变通的方式是, 我们看到通过PIP安装时会将包文件资源的整个路径显示出来,我们可以直接拷贝这个路径,然后用迅雷等下载工具进行下载:

下载完tensorflow二进制包后,我们可以看到,它的名字是有明显特征的,比如CP35表示对应的Python版本为3.5版.

安装二进制包的方法是,anaconda prompt进入到包所的目录,执行

 pip install tensorflow-2.3.1-cp35-cp35m-win_amd64.whl

验证的时候,如果遇到 "no module named tensorflow"

这个时候,在命令行下执行conda list查看,如果没有tensorflow等包,需要在conda下再次安装一遍

C:\Users\DELL>conda list
# packages in environment at C:\Users\DELL\Anaconda3:
#
_nb_ext_conf              0.2.0                    py35_0
absl-py                   0.13.0                    <pip>
alabaster                 0.7.8                    py35_0
anaconda                  4.1.1               np111py35_0
anaconda-client           1.4.0                    py35_0
anaconda-navigator        1.2.1                    py35_0
argcomplete               1.0.0                    py35_1
astropy                   1.2.1               np111py35_0
astunparse                1.6.3                     <pip>
babel                     2.3.3                    py35_0
backports                 1.0                      py35_0
beautifulsoup4            4.4.1                    py35_0
bitarray                  0.8.1                    py35_1
blaze                     0.10.1                   py35_0
bokeh                     0.12.0                   py35_0
boto                      2.40.0                   py35_0
bottleneck                1.1.0               np111py35_0
bzip2                     1.0.6                    vc14_3  [vc14]
cachetools                4.2.2                     <pip>
cffi                      1.6.0                    py35_0
chest                     0.2.3                    py35_0
click                     6.6                      py35_0
cloudpickle               0.2.1                    py35_0
clyent                    1.2.2                    py35_0
colorama                  0.3.7                    py35_0
comtypes                  1.1.2                    py35_0
conda                     4.1.6                    py35_0
conda-build               1.21.3                   py35_0
conda-env                 2.5.1                    py35_0
configobj                 5.0.6                    py35_0
console_shortcut          0.1.1                    py35_1
contextlib2               0.5.3                    py35_0
cryptography              1.4                      py35_0
curl                      7.49.0                   vc14_0  [vc14]
cycler                    0.10.0                   py35_0
cython                    0.24                     py35_0
cytoolz                   0.8.0                    py35_0
dask                      0.10.0                   py35_0
datashape                 0.5.2                    py35_0
decorator                 4.0.10                   py35_0
dill                      0.2.5                    py35_0
docutils                  0.12                     py35_2
dynd-python               0.7.2                    py35_0
entrypoints               0.2.2                    py35_0
et_xmlfile                1.0.1                    py35_0
fastcache                 1.0.2                    py35_1
flask                     0.11.1                   py35_0
flask-cors                2.1.2                    py35_0
freetype                  2.5.5                    vc14_1  [vc14]
gast                      0.3.3                     <pip>
get_terminal_size         1.0.0                    py35_0
gevent                    1.1.1                    py35_0
google-pasta              0.2.0                     <pip>
greenlet                  0.4.10                   py35_0
grpcio                    1.40.0                    <pip>
h5py                      2.10.0                    <pip>
h5py                      2.6.0               np111py35_0
hdf5                      1.8.15.1                 vc14_4  [vc14]
heapdict                  1.0.0                    py35_1
idna                      2.1                      py35_0
imagesize                 0.7.1                    py35_0
importlib-metadata        4.8.1                     <pip>
ipykernel                 4.3.1                    py35_0
ipython                   4.2.0                    py35_0
ipython_genutils          0.1.0                    py35_0
ipywidgets                4.1.1                    py35_0
itsdangerous              0.24                     py35_0
jdcal                     1.2                      py35_1
jedi                      0.9.0                    py35_1
jinja2                    2.8                      py35_1
jpeg                      8d                       vc14_0  [vc14]
jsonschema                2.5.1                    py35_0
jupyter                   1.0.0                    py35_3
jupyter_client            4.3.0                    py35_0
jupyter_console           4.1.1                    py35_0
jupyter_core              4.1.0                    py35_0
Keras-Preprocessing       1.1.2                     <pip>
libdynd                   0.7.2                         0
libpng                    1.6.22                   vc14_0  [vc14]
libtiff                   4.0.6                    vc14_2  [vc14]
llvmlite                  0.11.0                   py35_0
locket                    0.2.0                    py35_1
lxml                      3.6.0                    py35_0
Markdown                  3.3.4                     <pip>
markupsafe                0.23                     py35_2
matplotlib                1.5.1               np111py35_0
menuinst                  1.4.1                    py35_0
mistune                   0.7.2                    py35_0
mkl                       11.3.3                        1
mkl-service               1.1.2                    py35_2
mpmath                    0.19                     py35_1
multipledispatch          0.4.8                    py35_0
nb_anacondacloud          1.1.0                    py35_0
nb_conda                  1.1.0                    py35_0
nb_conda_kernels          1.0.3                    py35_0
nbconvert                 4.2.0                    py35_0
nbformat                  4.0.1                    py35_0
nbpresent                 3.0.2                    py35_0
networkx                  1.11                     py35_0
nltk                      3.2.1                    py35_0
nose                      1.3.7                    py35_1
notebook                  4.2.1                    py35_0
numba                     0.26.0              np111py35_0
numexpr                   2.6.0               np111py35_0
numpy                     1.11.1                   py35_0
numpy                     1.18.5                    <pip>
odo                       0.5.0                    py35_1
openpyxl                  2.3.2                    py35_0
openssl                   1.0.2h                   vc14_0  [vc14]
opt-einsum                3.3.0                     <pip>
pandas                    0.18.1              np111py35_0
partd                     0.3.4                    py35_0
path.py                   8.2.1                    py35_0
pathlib2                  2.1.0                    py35_0
patsy                     0.4.1                    py35_0
pep8                      1.7.0                    py35_0
pickleshare               0.7.2                    py35_0
pillow                    3.2.0                    py35_1
pip                       8.1.2                    py35_0
ply                       3.8                      py35_0
protobuf                  3.18.0                    <pip>
psutil                    4.3.0                    py35_0
py                        1.4.31                   py35_0
pyasn1                    0.1.9                    py35_0
pyasn1                    0.4.8                     <pip>
pyasn1-modules            0.2.8                     <pip>
pycosat                   0.6.1                    py35_1
pycparser                 2.14                     py35_1
pycrypto                  2.6.1                    py35_4
pycurl                    7.43.0                   py35_0
pyflakes                  1.2.3                    py35_0
pygments                  2.1.3                    py35_0
pyopenssl                 0.16.0                   py35_0
pyparsing                 2.1.4                    py35_0
pyqt                      4.11.4                   py35_6
pyreadline                2.1                      py35_0
pytables                  3.2.2               np111py35_4
pytest                    2.9.2                    py35_0
python                    3.5.2                         0
python-dateutil           2.5.3                    py35_0
pytz                      2016.4                   py35_0
pywin32                   220                      py35_1
pyyaml                    3.11                     py35_4
pyzmq                     15.2.0                   py35_0
qt                        4.8.7                    vc14_8  [vc14]
qtconsole                 4.2.1                    py35_0
qtpy                      1.0.2                    py35_0
requests                  2.10.0                   py35_0
rope                      0.9.4                    py35_1
rsa                       4.5                       <pip>
ruamel_yaml               0.11.7                   py35_0
scikit-image              0.12.3              np111py35_1
scikit-learn              0.17.1              np111py35_1
scipy                     0.17.1              np111py35_1
setuptools                23.0.0                   py35_0
simplegeneric             0.8.1                    py35_1
singledispatch            3.4.0.3                  py35_0
sip                       4.16.9                   py35_2
six                       1.10.0                   py35_0
six                       1.16.0                    <pip>
snowballstemmer           1.2.1                    py35_0
sockjs-tornado            1.0.3                    py35_0
sphinx                    1.4.1                    py35_0
sphinx_rtd_theme          0.1.9                    py35_0
spyder                    2.3.9                    py35_0
sqlalchemy                1.0.13                   py35_0
statsmodels               0.6.1               np111py35_1
sympy                     1.0                      py35_0
tensorboard-data-server   0.6.1                     <pip>
tensorboard-plugin-wit    1.8.0                     <pip>
tensorflow-estimator      2.3.0                     <pip>
termcolor                 1.1.0                     <pip>
tk                        8.5.18                   vc14_0  [vc14]
toolz                     0.8.0                    py35_0
tornado                   4.3                      py35_1
traitlets                 4.2.1                    py35_0
typing-extensions         3.10.0.2                  <pip>
unicodecsv                0.14.1                   py35_0
vs2015_runtime            14.0.25123                    0
werkzeug                  0.11.10                  py35_0
wheel                     0.29.0                   py35_0
wrapt                     1.12.1                    <pip>
xlrd                      1.0.0                    py35_0
xlsxwriter                0.9.2                    py35_0
xlwings                   0.7.2                    py35_0
xlwt                      1.1.2                    py35_0
zipp                      3.5.0                     <pip>
zlib                      1.2.8                    vc14_3  [vc14]

执行conda命令: conda install tensorflow

C:\Users\DELL>conda install tensorflow
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment C:\Users\DELL\Anaconda3:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    blas-1.0                   |              mkl           6 KB
    conda-env-2.6.0            |                0          498 B
    vs2015_runtime-14.0.25420  |                0         2.0 MB
    vc-14                      |                0          703 B
    libprotobuf-3.2.0          |           vc14_0         9.1 MB
    markdown-2.6.9             |           py35_0         101 KB
    requests-2.14.2            |           py35_0         705 KB
    ruamel_yaml-0.11.14        |           py35_1         221 KB
    backports.weakref-1.0rc1   |           py35_0           8 KB
    html5lib-0.9999999         |           py35_0         185 KB
    protobuf-3.2.0             |           py35_0         463 KB
    bleach-1.5.0               |           py35_0          22 KB
    pyopenssl-16.2.0           |           py35_0          70 KB
    tensorflow-1.2.1           |           py35_0        21.0 MB
    conda-4.3.30               |   py35hec795fb_0         541 KB
    ------------------------------------------------------------
                                           Total:        34.4 MB

The following NEW packages will be INSTALLED:

    backports.weakref: 1.0rc1-py35_0
    blas:              1.0-mkl
    bleach:            1.5.0-py35_0
    html5lib:          0.9999999-py35_0
    libprotobuf:       3.2.0-vc14_0
    markdown:          2.6.9-py35_0
    protobuf:          3.2.0-py35_0
    tensorflow:        1.2.1-py35_0
    vc:                14-0

The following packages will be UPDATED:

    conda:             4.1.6-py35_0     --> 4.3.30-py35hec795fb_0
    conda-env:         2.5.1-py35_0     --> 2.6.0-0
    pyopenssl:         0.16.0-py35_0    --> 16.2.0-py35_0
    requests:          2.10.0-py35_0    --> 2.14.2-py35_0
    ruamel_yaml:       0.11.7-py35_0    --> 0.11.14-py35_1
    vs2015_runtime:    14.0.25123-0     --> 14.0.25420-0

Proceed ([y]/n)? y

Fetching packages ...
blas-1.0-mkl.t 100% |###############################| Time: 0:00:00   2.10 MB/s
conda-env-2.6. 100% |###############################| Time: 0:00:00 251.87 kB/s
vs2015_runtime 100% |###############################| Time: 0:00:02 748.93 kB/s
vc-14-0.tar.bz 100% |###############################| Time: 0:00:00 408.96 kB/s
libprotobuf-3. 100% |###############################| Time: 0:00:02   4.00 MB/s
markdown-2.6.9 100% |###############################| Time: 0:00:00 447.80 kB/s
requests-2.14. 100% |###############################| Time: 0:00:00 865.03 kB/s
ruamel_yaml-0. 100% |###############################| Time: 0:00:00 528.02 kB/s
backports.weak 100% |###############################| Time: 0:00:00   2.12 MB/s
html5lib-0.999 100% |###############################| Time: 0:00:00 207.23 kB/s
protobuf-3.2.0 100% |###############################| Time: 0:00:00 645.29 kB/s
bleach-1.5.0-p 100% |###############################| Time: 0:00:00   1.02 MB/s
pyopenssl-16.2 100% |###############################| Time: 0:00:00 364.58 kB/s
tensorflow-1.2 100% |###############################| Time: 0:00:07   2.84 MB/s
conda-4.3.30-p 100% |###############################| Time: 0:00:00 723.63 kB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%

C:\Users\DELL>

此时,再次执行conda list,发现tensorflow已经存在:

 这时,再次执行import tensorflow as tf,不再报错:

还有两个命令或许对上面的问题有效:

conda create -n tensorflow-cpu tensorflow
activate tensorflow-cpu
(C:\Users\DELL\Anaconda3) C:\Users\DELL>conda create -n tensorflow-cpu
Fetching package metadata .............
Solving package specifications:
Package plan for installation in environment C:\Users\DELL\Anaconda3\envs\tensorflow-cpu:

Proceed ([y]/n)? y

#
# To activate this environment, use:
# > activate tensorflow-cpu
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#


(C:\Users\DELL\Anaconda3) C:\Users\DELL>conda activate tensorflow-cpu

CommandNotFoundError: 'activate'


(C:\Users\DELL\Anaconda3) C:\Users\DELL>activate tensorflow-cpu

(tensorflow-cpu) C:\Users\DELL>
(tensorflow-cpu) C:\Users\DELL>

这里 激活 开发环境是指,在 Anaconda 下我们可以有多个开发环境,比如如果你想对比一下 CPU 和 GPU 计算速度的差距,可以同时安装 2 个开发环境,然后根据需要切换到 CPU 开发环境,或者 GPU 开发环境,非常方便。如果不用 Anaconda 而是一个 Python 裸奔的话,要么使用 VirtualEnv,要么就只能反复安装卸载不同的开发环境了。

跑minist网络用例:

执行一段绘图程序:

安装ONNX

安装onnx需要依赖cmake,所以首先安装cmake

pip install cmake
pip install onnx==1.8.1
C:\Users\DELL>pip install cmake
Collecting cmake
  Downloading https://files.pythonhosted.org/packages/d3/7e/8fc8632ef7de5c3443af88d58147a6ae32f3386a5b5ee5f473847e59e700/cmake-3.21.2-py2.py3-none-win_amd64.whl (37.3MB)
    100% |████████████████████████████████| 37.3MB 34kB/s
Installing collected packages: cmake
Successfully installed cmake-3.21.2
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\DELL>pip install onnx==1.8.1
Collecting onnx==1.8.1
  Downloading https://files.pythonhosted.org/packages/ec/c7/422de621ed9a5a56c166b0456c585f463e04802a7d281067ee97334fc387/onnx-1.8.1-cp35-cp35m-win_amd64.whl (6.9MB)
    100% |████████████████████████████████| 6.9MB 213kB/s
Collecting typing>=3.6.4 (from onnx==1.8.1)
  Downloading https://files.pythonhosted.org/packages/f2/5d/865e17349564eb1772688d8afc5e3081a5964c640d64d1d2880ebaed002d/typing-3.10.0.0-py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): typing-extensions>=3.6.2.1 in c:\users\dell\anaconda3\lib\site-packages (from onnx==1.8.1)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.16.6 in c:\users\dell\anaconda3\lib\site-packages (from onnx==1.8.1)
Requirement already satisfied (use --upgrade to upgrade): six in c:\users\dell\anaconda3\lib\site-packages (from onnx==1.8.1)
Requirement already satisfied (use --upgrade to upgrade): protobuf in c:\users\dell\anaconda3\lib\site-packages (from onnx==1.8.1)
Installing collected packages: typing, onnx
Successfully installed onnx-1.8.1 typing-3.10.0.0
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\DELL>

测试发现,安装onnx 1.8.1版本才能成功,其它的版本都会失败.

安装剩余的软件包

C:\Users\DELL>pip install numpy scipy sklearn pandas pillow matplotlib keras  -i https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied (use --upgrade to upgrade): numpy in c:\users\dell\anaconda3\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): scipy in c:\users\dell\anaconda3\lib\site-packages
Collecting sklearn
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Requirement already satisfied (use --upgrade to upgrade): pandas in c:\users\dell\anaconda3\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): pillow in c:\users\dell\anaconda3\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): matplotlib in c:\users\dell\anaconda3\lib\site-packages
Collecting keras
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5a/38/04d9b7fb53acdf861df2c4505fa96b06c779817a511e94b8882d284ba360/keras-2.6.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in c:\users\dell\anaconda3\lib\site-packages (from sklearn)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil>=2 in c:\users\dell\anaconda3\lib\site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in c:\users\dell\anaconda3\lib\site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): cycler in c:\users\dell\anaconda3\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.4,>=1.5.6 in c:\users\dell\anaconda3\lib\site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in c:\users\dell\anaconda3\lib\site-packages (from python-dateutil>=2->pandas)
Building wheels for collected packages: sklearn
  Running setup.py bdist_wheel for sklearn ... done
  Stored in directory: C:\Users\DELL\AppData\Local\pip\Cache\wheels\6f\cd\11\f6acd1062135d70bc0a7066808561580d256b3149055cb33ad
Successfully built sklearn
Installing collected packages: sklearn, keras
Successfully installed keras-2.6.0 sklearn-0.0
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\DELL>

抓取MINST数据集并输出

​
#coding:utf-8
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) #MNIST数据输入
X_train = mnist.train.images
y_train = mnist.train.labels
X_test = mnist.test.images
y_test = mnist.test.labels

# 输入图像大小是 28x28 大小
X_train = X_train.reshape([-1, 28, 28, 1])
X_test = X_test.reshape([-1, 28, 28, 1])
plt.imshow(X_train[0].reshape((28, 28)), cmap='gray')
plt.imshow(X_train[1].reshape((28, 28)), cmap='gray')
plt.imshow(X_train[2].reshape((28, 28)), cmap='gray')
print ('输入数据打shape:',mnist.train.images.shape)
print ('输入数据打shape:',mnist.test.images.shape)
print ('输入数据打shape:',mnist.validation.images.shape)


安装tf2onnx

C:\Users\DELL>pip install tf2onnx
Collecting tf2onnx
  Downloading https://files.pythonhosted.org/packages/46/52/fa6a3af9f8ea0560d460d727096edc1453b11daeb226d1093aa93e27ebcc/tf2onnx-1.9.2-py3-none-any.whl (430kB)
    100% |████████████████████████████████| 440kB 585kB/s
Collecting flatbuffers~=1.12 (from tf2onnx)
  Downloading https://files.pythonhosted.org/packages/eb/26/712e578c5f14e26ae3314c39a1bdc4eb2ec2f4ddc89b708cf8e0a0d20423/flatbuffers-1.12-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): requests in c:\users\dell\anaconda3\lib\site-packages (from tf2onnx)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.14.1 in c:\users\dell\anaconda3\lib\site-packages (from tf2onnx)
Requirement already satisfied (use --upgrade to upgrade): onnx>=1.4.1 in c:\users\dell\anaconda3\lib\site-packages (from tf2onnx)
Requirement already satisfied (use --upgrade to upgrade): six in c:\users\dell\anaconda3\lib\site-packages (from tf2onnx)
Requirement already satisfied (use --upgrade to upgrade): typing>=3.6.4 in c:\users\dell\anaconda3\lib\site-packages (from onnx>=1.4.1->tf2onnx)
Requirement already satisfied (use --upgrade to upgrade): protobuf in c:\users\dell\anaconda3\lib\site-packages (from onnx>=1.4.1->tf2onnx)
Requirement already satisfied (use --upgrade to upgrade): typing-extensions>=3.6.2.1 in c:\users\dell\anaconda3\lib\site-packages (from onnx>=1.4.1->tf2onnx)
Installing collected packages: flatbuffers, tf2onnx
Successfully installed flatbuffers-1.12 tf2onnx-1.9.2
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\DELL>pip install asserts
Collecting asserts
  Downloading https://files.pythonhosted.org/packages/15/ef/a02b2af8228be2a08ffd7e7630084e441030fbd3e6426483ddcdf905ac34/asserts-0.11.1-py2.py3-none-any.whl
Installing collected packages: asserts
Successfully installed asserts-0.11.1
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\DELL>

安装keras

C:\Users\DELL>conda install keras
Fetching package metadata .............
Solving package specifications: .

Package plan for installation in environment C:\Users\DELL\Anaconda3:

The following NEW packages will be INSTALLED:

    keras:               2.2.2-0
    keras-applications:  1.0.4-py35_1
    keras-base:          2.2.2-py35_0
    keras-preprocessing: 1.0.2-py35_1
    patch:               2.5.9-1

The following packages will be UPDATED:

    anaconda:            4.1.1-np111py35_0     --> custom-py35_0
    conda:               4.3.30-py35hec795fb_0 --> 4.5.11-py35_0
    conda-env:           2.6.0-0               --> 2.6.0-1
    pycosat:             0.6.1-py35_1          --> 0.6.3-py35hfa6e2cd_0

Proceed ([y]/n)?

keras-applicat 100% |###############################| Time: 0:00:00 292.58 kB/s
keras-preproce 100% |###############################| Time: 0:00:00 959.92 kB/s
keras-base-2.2 100% |###############################| Time: 0:00:00   1.03 MB/s
keras-2.2.2-0. 100% |###############################| Time: 0:00:00   3.03 MB/s

C:\Users\DELL>conda install keras

结束!