Tensorflow入门笔记【一】环境

1、傻瓜式集成环境anaconda安装

(1)WINDOWS环境下,只能使用python3.5(64bit)

(2)暂时推荐Anoconda3-4.2.0-windows-x86_64。目前我是基于该版本学习,其他版本没有试过

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86_64.exe

【延伸:清华大学开源软件镜像站 使用技巧(待补充)】

2、tensorflow库安装

2.1 使用conda 安装tensorflow

(1)使用管理员权限,打开anaconda prompt

(2)执行conda install tensorflow。以下是正常安装的提示

【注意:尝试过其他anaconda版本下,执行2.1-(2)的命令会出现我暂时不理解的错误】

(3)【然而,最后还是因为网络不好,所以没能成功。】

2.2 使用清华镜像源安装tensorflow

(1)执行如下命令,给conda的配置文件添加镜像源路径:

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

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

【注意】我的anaconda安装在D盘(暂不清晰接下来描述的现象与此是否有关),执行命令后提示如下错误

显然,配置文件的路径为空。

错误提示缺乏.condarc这个文件。应该就是conda的config file了。

那么,自然的,去创建相应的目录和文件后再运行

再次,运营上述命令,不再报错。

(2)执行config --set show_channel_urls yes

(3)执行pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow

【安装成功。提示信息见最末尾附录一】

3、测试tensorflow是否安装成功

(1)打开Jupiter Notebook,看到如下命令行窗口弹出后,耐心等待(因设备性能差异,窗口弹出后可能会出现没有任何打印信息的情况,我的设备目前是约15s左右,出现如下打印信息,就会弹出web应用);

(2)Jupyter Notebook在浏览器打开,其默认文件存储路径为C盘【我的文档】

(3)如下窗口所示,新建python[conda root],文件中输入“import tensorflow”后运行,如无提示错误,则安装成功

【然而,因为我的系统没有安装visual studio相关环境插件,报如下错误】

ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" ...

按错误提示,去“https://support.microsoft.com/zh-cn/help/2977003/the-latest-supported-visual-c-downloads”处下载相应的VS环境插件就好了。我是64位系统,所以选择x64版本:

下载安装后,按提示重启电脑,即可解决问题。

【如有碰到其余问题,欢迎在评论区留言】

 

 

【附录一:使用清华镜像下载tensorflow。有空再来研习所下载的每一个库的作用】

Collecting tensorflow
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e9/58/25a8d09901992596f057c22ef17832f2f57ea4d84b994f92ea88d0c49ca3/tensorflow-2.2.0-cp35-cp35m-win_amd64.whl (459.1MB)
    100% |████████████████████████████████| 459.1MB 2.6kB/s
Collecting grpcio>=1.8.6 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9a/70/47389dc7521426e021159b4ca275761070c2788ede6dcc385f18957a8a47/grpcio-1.29.0-cp35-cp35m-win_amd64.whl (2.4MB)
    100% |████████████████████████████████| 2.4MB 508kB/s
Collecting astunparse==1.6.3 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2b/03/13dde6512ad7b4557eb792fbcf0c653af6076b81e5941d36ec61f7ce6028/astunparse-1.6.3-py2.py3-none-any.whl
Collecting scipy==1.4.1; python_version >= "3" (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ef/ae/78bbaf498bba92e5ce5903b096b75b5e1f9f82a742fc37a6595892f1ffca/scipy-1.4.1-cp35-cp35m-win_amd64.whl (30.8MB)
    100% |████████████████████████████████| 30.8MB 43kB/s
Collecting numpy<2.0,>=1.16.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ed/09/ff8f529a5548ff788765f66a81ef751130f26f8c7d517e94d3dbf3ba1ed5/numpy-1.18.5-cp35-cp35m-win_amd64.whl (12.7MB)
    100% |████████████████████████████████| 12.7MB 90kB/s
Collecting google-pasta>=0.1.8 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/de/c648ef6835192e6e2cc03f40b19eeda4382c49b5bafb43d88b931c4c74ac/google_pasta-0.2.0-py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 4.7MB/s
Collecting six>=1.12.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Collecting keras-preprocessing>=1.1.0 (from tensorflow)
  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.1MB/s
Collecting protobuf>=3.8.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f8/4c/f66908eeadfb7a2e41a462fae7f925aa7b54cf555ef331e4b45e59b6859d/protobuf-3.12.2-cp35-cp35m-win_amd64.whl (1.1MB)
    100% |████████████████████████████████| 1.1MB 616kB/s
Collecting absl-py>=0.7.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1a/53/9243c600e047bd4c3df9e69cfabc1e8004a82cac2e0c484580a78a94ba2a/absl-py-0.9.0.tar.gz (104kB)
    100% |████████████████████████████████| 112kB 2.1MB/s
Collecting tensorflow-estimator<2.3.0,>=2.2.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/f5/926ae53d6a226ec0fda5208e0e581cffed895ccc89e36ba76a8e60895b78/tensorflow_estimator-2.2.0-py2.py3-none-any.whl (454kB)
    100% |████████████████████████████████| 460kB 520kB/s
Collecting opt-einsum>=2.3.2 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/63/a5/e6c07b08b934831ccb8c98ee335e66b7761c5754ee3cabfe4c11d0b1af28/opt_einsum-3.2.1-py3-none-any.whl (63kB)
    100% |████████████████████████████████| 71kB 2.0MB/s
Collecting gast==0.3.3 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/84/759f5dd23fec8ba71952d97bcc7e2c9d7d63bdc582421f3cd4be845f0c98/gast-0.3.3-py2.py3-none-any.whl
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Collecting wrapt>=1.11.1 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/82/f7/e43cefbe88c5fd371f4cf0cf5eb3feccd07515af9fd6cf7dbf1d1793a797/wrapt-1.12.1.tar.gz
Collecting tensorboard<2.3.0,>=2.2.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1d/74/0a6fcb206dcc72a6da9a62dd81784bfdbff5fedb099982861dc2219014fb/tensorboard-2.2.2-py3-none-any.whl (3.0MB)
    100% |████████████████████████████████| 3.0MB 310kB/s
Requirement already satisfied (use --upgrade to upgrade): wheel>=0.26; python_version >= "3" in d:\program files\anaconda\lib\site-packages (from tensorflow)
Collecting h5py<2.11.0,>=2.10.0 (from tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/25/81/be3e43b143ee6b40cebb3d6e61da8ce74a03221791134f16dd016a497c23/h5py-2.10.0-cp35-cp35m-win_amd64.whl (2.4MB)
    100% |████████████████████████████████| 2.4MB 409kB/s
Requirement already satisfied (use --upgrade to upgrade): setuptools in d:\program files\anaconda\lib\site-packages\setuptools-27.2.0-py3.5.egg (from protobuf>=3.8.0->tensorflow)
Collecting tensorboard-plugin-wit>=1.6.0 (from tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/51/cd/a0c1f9e4582ea64dddf76c1b808b318d01e3b858a51c715bffab1016ecc7/tensorboard_plugin_wit-1.6.0.post3-py3-none-any.whl (777kB)
    100% |████████████████████████████████| 778kB 800kB/s
Collecting markdown>=2.6.8 (from tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/63/eaec2bd025ab48c754b55e8819af0f6a69e2b1e187611dd40cbbe101ee7f/Markdown-3.2.2-py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 1.4MB/s
Collecting werkzeug>=0.11.15 (from tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298kB)
    100% |████████████████████████████████| 307kB 1.3MB/s
Collecting google-auth-oauthlib<0.5,>=0.4.1 (from tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7b/b8/88def36e74bee9fce511c9519571f4e485e890093ab7442284f4ffaef60b/google_auth_oauthlib-0.4.1-py2.py3-none-any.whl
Collecting requests<3,>=2.21.0 (from tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1a/70/1935c770cb3be6e3a8b78ced23d7e0f3b187f5cbfab4749523ed65d7c9b1/requests-2.23.0-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 1.5MB/s
Collecting google-auth<2,>=1.6.3 (from tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9f/87/8f8d09ba959b2e51508cfcf3350e7df6ed0d1e06c7e056ca1a28e00e982a/google_auth-1.17.2-py2.py3-none-any.whl (90kB)
    100% |████████████████████████████████| 92kB 1.9MB/s
Collecting importlib-metadata; python_version < "3.8" (from markdown>=2.6.8->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/98/13/a1d703ec396ade42c1d33df0e1cb691a28b7c08b336a5683912c87e04cd7/importlib_metadata-1.6.1-py2.py3-none-any.whl
Collecting requests-oauthlib>=0.7.0 (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/12/b92740d845ab62ea4edf04d2f4164d82532b5a0b03836d4d4e71c6f3d379/requests_oauthlib-1.3.0-py2.py3-none-any.whl
Collecting chardet<4,>=3.0.2 (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 86kB/s
Collecting idna<3,>=2.5 (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/89/e3/afebe61c546d18fb1709a61bee788254b40e736cff7271c7de5de2dc4128/idna-2.9-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 183kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e1/e5/df302e8017440f111c11cc41a6b432838672f5a70aa29227bf58149dc72f/urllib3-1.25.9-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 266kB/s
Collecting certifi>=2017.4.17 (from requests<3,>=2.21.0->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/98/99/def511020aa8f663d4a2cfaa38467539e864799289ff354569e339e375b1/certifi-2020.4.5.2-py2.py3-none-any.whl (157kB)
    100% |████████████████████████████████| 163kB 513kB/s
Collecting pyasn1-modules>=0.2.1 (from google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/95/de/214830a981892a3e286c3794f41ae67a4495df1108c3da8a9f62159b9a9d/pyasn1_modules-0.2.8-py2.py3-none-any.whl (155kB)
    100% |████████████████████████████████| 163kB 269kB/s
Collecting cachetools<5.0,>=2.0.0 (from google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b3/59/524ffb454d05001e2be74c14745b485681c6ed5f2e625f71d135704c0909/cachetools-4.1.0-py3-none-any.whl
Collecting rsa<5,>=3.1.4; python_version >= "3" (from google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9b/95/c62b736e9d474bc5c6847bf1449d6091ff413aee136af7356c3cdeee141a/rsa-4.6-py2.py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->markdown>=2.6.8->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b2/34/bfcb43cc0ba81f527bc4f40ef41ba2ff4080e047acb0586b56b3d017ace4/zipp-3.1.0-py3-none-any.whl
Collecting oauthlib>=3.0.0 (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/05/57/ce2e7a8fa7c0afb54a0581b14a65b56e62b5759dbc98e80627142b8a3704/oauthlib-3.1.0-py2.py3-none-any.whl (147kB)
    100% |████████████████████████████████| 153kB 1.1MB/s
Collecting pyasn1<0.5.0,>=0.4.6 (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77kB)
    100% |████████████████████████████████| 81kB 1.3MB/s
Building wheels for collected packages: absl-py, termcolor, wrapt
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: C:\Users\SEASON\AppData\Local\pip\Cache\wheels\55\fd\b5\4db4cce08516c3aaa68ee4c843439f45c7fcf177320ba63d9f
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: C:\Users\SEASON\AppData\Local\pip\Cache\wheels\e3\d8\fc\50ab6e66e3dead21d5afff006dc5298913a3064be2b1105359
  Running setup.py bdist_wheel for wrapt ... done
  Stored in directory: C:\Users\SEASON\AppData\Local\pip\Cache\wheels\68\e3\d7\4b6eee6f5d547bdfd97ba406128db66c5654dfb831fda163a2
Successfully built absl-py termcolor wrapt
Installing collected packages: six, grpcio, astunparse, numpy, scipy, google-pasta, keras-preprocessing, protobuf, absl-py, tensorflow-estimator, opt-einsum, gast, termcolor, wrapt, tensorboard-plugin-wit, zipp, importlib-metadata, markdown, werkzeug, oauthlib, chardet, idna, urllib3, certifi, requests, requests-oauthlib, pyasn1, pyasn1-modules, cachetools, rsa, google-auth, google-auth-oauthlib, tensorboard, h5py, tensorflow
  Found existing installation: six 1.10.0
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling six-1.10.0:
      Successfully uninstalled six-1.10.0
  Found existing installation: numpy 1.11.1
    Uninstalling numpy-1.11.1:
      Successfully uninstalled numpy-1.11.1
  Found existing installation: scipy 0.18.1
    Uninstalling scipy-0.18.1:
      Successfully uninstalled scipy-0.18.1
  Found existing installation: wrapt 1.10.6
    DEPRECATION: Uninstalling a distutils installed project (wrapt) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling wrapt-1.10.6:
      Successfully uninstalled wrapt-1.10.6
  Found existing installation: Werkzeug 0.11.11
    DEPRECATION: Uninstalling a distutils installed project (werkzeug) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling Werkzeug-0.11.11:
      Successfully uninstalled Werkzeug-0.11.11
  Found existing installation: idna 2.1
    Uninstalling idna-2.1:
      Successfully uninstalled idna-2.1
  Found existing installation: requests 2.11.1
    Uninstalling requests-2.11.1:
      Successfully uninstalled requests-2.11.1
  Found existing installation: pyasn1 0.1.9
    DEPRECATION: Uninstalling a distutils installed project (pyasn1) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling pyasn1-0.1.9:
      Successfully uninstalled pyasn1-0.1.9
  Found existing installation: h5py 2.6.0
    Uninstalling h5py-2.6.0:
      Successfully uninstalled h5py-2.6.0
Successfully installed absl-py-0.9.0 astunparse-1.6.3 cachetools-4.1.0 certifi-2020.4.5.2 chardet-3.0.4 gast-0.3.3 google-auth-1.17.2 google-auth-oauthlib-0.4.1 google-pasta-0.2.0 grpcio-1.29.0 h5py-2.10.0 idna-2.9 importlib-metadata-1.6.1 keras-preprocessing-1.1.2 markdown-3.2.2 numpy-1.18.5 oauthlib-3.1.0 opt-einsum-3.2.1 protobuf-3.12.2 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.23.0 requests-oauthlib-1.3.0 rsa-4.6 scipy-1.4.1 six-1.15.0 tensorboard-2.2.2 tensorboard-plugin-wit-1.6.0.post3 tensorflow-2.2.0 tensorflow-estimator-2.2.0 termcolor-1.1.0 urllib3-1.25.9 werkzeug-1.0.1 wrapt-1.12.1 zipp-3.1.0

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值