创建于:2020.03.04
修改于:2020.03.05
win10 64bit中已经安装了Anaconda 4.8.2,由于需要运行Jupyter notebook中的工程,需要安装tensorflow。
安装CPU版本还是GPU版本,需要自己定夺。
若想安装GPU版本,需要查看硬件是否满足。详细请参考查看电脑显卡(GPU)是否支持CUDA
(1)检测anaconda环境:确定下总不是坏事。
(2)检测目前安装了哪些环境变量:检查是否已经安装了有关tensorflow的环境。
(base) C:\Windows\system32>conda --version
conda 4.8.2
(base) C:\Windows\system32>conda info --envs
# conda environments:
#
base * C:\ProgramData\Anaconda3
(base) C:\Windows\system32>python --version
Python 3.6.5 :: Anaconda, Inc.
(base) C:\Windows\system32>
(3)查看当前有哪些可以使用的tensorflow版本
conda search --full --name tensorflow
conda search --full --name tensorflow-gpu
(base) C:\Windows\system32>conda search --full --name tensorflow
Loading channels: done
# Name Version Build Channel
tensorflow 1.7.0 0 pkgs/main
tensorflow 1.7.1 0 pkgs/main
tensorflow 1.8.0 0 pkgs/main
tensorflow 1.9.0 eigen_py35hb0e21f4_1 pkgs/main
tensorflow 1.9.0 eigen_py36h0b764b7_1 pkgs/main
tensorflow 1.9.0 gpu_py35h0075c17_1 pkgs/main
tensorflow 1.9.0 gpu_py36hfdee9c2_1 pkgs/main
tensorflow 1.10.0 eigen_py35h38c8211_0 pkgs/main
tensorflow 1.10.0 eigen_py36h849fbd8_0 pkgs/main
tensorflow 1.10.0 gpu_py35ha5d5ef7_0 pkgs/main
tensorflow 1.10.0 gpu_py36h3514669_0 pkgs/main
tensorflow 1.10.0 mkl_py35h4a0f5c2_0 pkgs/main
tensorflow 1.10.0 mkl_py36hb361250_0 pkgs/main
tensorflow 1.11.0 eigen_py36h346fd36_0 pkgs/main
tensorflow 1.11.0 gpu_py36h5dc63e2_0 pkgs/main
tensorflow 1.11.0 mkl_py36h41bbc20_0 pkgs/main
tensorflow 1.12.0 eigen_py36h67ac661_0 pkgs/main
tensorflow 1.12.0 gpu_py36ha5f9131_0 pkgs/main
tensorflow 1.12.0 mkl_py36h4f00353_0 pkgs/main
tensorflow 1.13.1 eigen_py36hf0a88a9_0 pkgs/main
tensorflow 1.13.1 eigen_py37h2a8d240_0 pkgs/main
tensorflow 1.13.1 gpu_py36h1635174_0 pkgs/main
tensorflow 1.13.1 gpu_py36h9006a92_0 pkgs/main
tensorflow 1.13.1 gpu_py37h83e5d6a_0 pkgs/main
tensorflow 1.13.1 gpu_py37hbc1a9d5_0 pkgs/main
tensorflow 1.13.1 mkl_py36hd212fbe_0 pkgs/main
tensorflow 1.13.1 mkl_py37h9463c59_0 pkgs/main
tensorflow 1.14.0 eigen_py36hf4fd08c_0 pkgs/main
tensorflow 1.14.0 eigen_py37hcf3f253_0 pkgs/main
tensorflow 1.14.0 gpu_py36h305fd99_0 pkgs/main
tensorflow 1.14.0 gpu_py36heb2afb7_0 pkgs/main
tensorflow 1.14.0 gpu_py37h2fabf85_0 pkgs/main
tensorflow 1.14.0 gpu_py37h5512b17_0 pkgs/main
tensorflow 1.14.0 mkl_py36hb88db5b_0 pkgs/main
tensorflow 1.14.0 mkl_py37h7908ca0_0 pkgs/main
tensorflow 1.15.0 eigen_py36h932cce6_0 pkgs/main
tensorflow 1.15.0 eigen_py37h9f89a44_0 pkgs/main
tensorflow 1.15.0 gpu_py36h2b26d6b_0 pkgs/main
tensorflow 1.15.0 gpu_py37hc3743a6_0 pkgs/main
tensorflow 1.15.0 mkl_py36h997801b_0 pkgs/main
tensorflow 1.15.0 mkl_py37h3789bd0_0 pkgs/main
tensorflow 2.0.0 eigen_py36h457aea3_0 pkgs/main
tensorflow 2.0.0 eigen_py37hbfc5123_0 pkgs/main
tensorflow 2.0.0 gpu_py36hfdd5754_0 pkgs/main
tensorflow 2.0.0 gpu_py37h57d29ca_0 pkgs/main
tensorflow 2.0.0 mkl_py36h781710d_0 pkgs/main
tensorflow 2.0.0 mkl_py37he1bbcac_0 pkgs/main
tensorflow 2.1.0 eigen_py36hdbbabfe_0 pkgs/main
tensorflow 2.1.0 eigen_py37hd727fc0_0 pkgs/main
tensorflow 2.1.0 gpu_py36h3346743_0 pkgs/main
tensorflow 2.1.0 gpu_py37h7db9008_0 pkgs/main
tensorflow 2.1.0 mkl_py36h31ad7c1_0 pkgs/main
tensorflow 2.1.0 mkl_py37ha977152_0 pkgs/main
(base) C:\Windows\system32>conda search --full --name tensorflow-gpu
Loading channels: done
# Name Version Build Channel
tensorflow-gpu 1.8.0 h21ff451_0 pkgs/main
tensorflow-gpu 1.9.0 hf154084_0 pkgs/main
tensorflow-gpu 1.10.0 hf154084_0 pkgs/main
tensorflow-gpu 1.11.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.12.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.13.1 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.14.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.15.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 2.0.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 2.1.0 h0d30ee6_0 pkgs/main
(base) C:\Windows\system32>
(4) 查看tensorflow包信息及依赖关系
conda info tensorflow
(1)查看Python版本
(base) C:\Windows\system32>python --version
Python 3.6.5 :: Anaconda, Inc.
(2)安装
在Anaconda Prompt中利用Anaconda创建一个python3.6的环境,环境名称为tensorflow2.1(准备安装2.1版本 cpu版)
(base) C:\Windows\system32>conda create -n tensorflow2.1 python=3.6
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\ProgramData\Anaconda3\envs\tensorflow2.1
added / updated specs:
- python=3.6
The following packages will be downloaded:
package | build
---------------------------|-----------------
certifi-2019.11.28 | py36_0 157 KB
pip-20.0.2 | py36_1 1.9 MB
python-3.6.10 | h9f7ef89_0 20.3 MB
setuptools-45.2.0 | py36_0 695 KB
sqlite-3.31.1 | he774522_0 961 KB
wheel-0.34.2 | py36_0 67 KB
------------------------------------------------------------
Total: 24.1 MB
The following NEW packages will be INSTALLED:
certifi pkgs/main/win-64::certifi-2019.11.28-py36_0
pip pkgs/main/win-64::pip-20.0.2-py36_1
python pkgs/main/win-64::python-3.6.10-h9f7ef89_0
setuptools pkgs/main/win-64::setuptools-45.2.0-py36_0
sqlite pkgs/main/win-64::sqlite-3.31.1-he774522_0
vc pkgs/main/win-64::vc-14.1-h0510ff6_4
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.16.27012-hf0eaf9b_1
wheel pkgs/main/win-64::wheel-0.34.2-py36_0
wincertstore pkgs/main/win-64::wincertstore-0.2-py36h7fe50ca_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
python-3.6.10 | 20.3 MB | ############################################################################ | 100%
sqlite-3.31.1 | 961 KB | ############################################################################ | 100%
pip-20.0.2 | 1.9 MB | ############################################################################ | 100%
certifi-2019.11.28 | 157 KB | ############################################################################ | 100%
wheel-0.34.2 | 67 KB | ############################################################################ | 100%
setuptools-45.2.0 | 695 KB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate tensorflow2.1
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) C:\Windows\system32>
(3)在Anaconda Prompt中启动tensorflow2.1环境
activate tensorflow2.1
(base) C:\Windows\system32>activate tensorflow2.1
(tensorflow2.1) C:\Windows\system32>
(4)检测tensorflow2.1的环境添加到了Anaconda里面
conda info --envs
看到下面已经创建成功。
(tensorflow2.1) C:\Windows\system32>conda info --envs
# conda environments:
#
base C:\ProgramData\Anaconda3
tensorflow2.1 * C:\ProgramData\Anaconda3\envs\tensorflow2.1
(5)检测当前环境中的python的版本
python --version
(tensorflow2.1) C:\Windows\system32>python --version
Python 3.6.10 :: Anaconda, Inc.
(6)在tensorflow2.1环境中正式安装tensorflow包
包大小为355.9 MB,请确保网络连接稳定流畅。
pip install --upgrade --ignore-installed tensorflow==2.1.0
Building wheel for termcolor (setup.py) ... done
Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4835 sha256=1b2b724cd37b38fdf2e608760768510794309f21b0f0986e0d5499eb24743602
Stored in directory: c:\users\chenlim\appdata\local\pip\cache\wheels\93\2a\eb\e58dbcbc963549ee4f065ff80a59f274cc7210b6eab962acdc
Successfully built absl-py gast wrapt termcolor
Installing collected packages: numpy, opt-einsum, six, setuptools, markdown, absl-py, werkzeug, pyasn1, rsa, pyasn1-modules, cachetools, google-auth, idna, chardet, certifi, urllib3, requests, oauthlib, requests-oauthlib, google-auth-oauthlib, protobuf, grpcio, wheel, tensorboard, google-pasta, astor, gast, keras-preprocessing, wrapt, termcolor, h5py, keras-applications, scipy, tensorflow-estimator, tensorflow
Successfully installed absl-py-0.9.0 astor-0.8.1 cachetools-4.0.0 certifi-2019.11.28 chardet-3.0.4 gast-0.2.2 google-auth-1.11.2 google-auth-oauthlib-0.4.1 google-pasta-0.1.8 grpcio-1.27.2 h5py-2.10.0 idna-2.9 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 numpy-1.18.1 oauthlib-3.1.0 opt-einsum-3.2.0 protobuf-3.11.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.23.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 setuptools-45.2.0.post20200210 six-1.14.0 tensorboard-2.1.1 tensorflow-2.1.0 tensorflow-estimator-2.1.0 termcolor-1.1.0 urllib3-1.25.8 werkzeug-1.0.0 wheel-0.34.2 wrapt-1.12.0
(tensorflow2.1) C:\Windows\system32>python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf #不报错就表示安装成功
>>> exit()
我这报错了,内容如下:
ImportError: DLL load failed: 找不到指定的模块。
我改成安装2.0.0版本,结果正确。详情参见下面连接。
win10下,tensorflow cpu版本报错:ImportError: DLL load failed: 找不到指定的模块
(8)虚拟环境的退出、进入、删除
退出 tensflow的tensorflow2.1环境:conda deactivate
激活 tensflow的tensorflow2.1环境:activate tensorflow2.1
删除 tensflow的tensorflow2.1环境:conda remove --name tensorflow2.1 --all
(1)激活拟要安装ipython和jupyter的虚拟环境;
(2)在对应的虚拟环境中安装ipython和jupyter;
(3)打开工程项目,即可运行成功。
(tf2.0) C:\Windows\system32>conda install ipython
(tf2.0) C:\Windows\system32>conda install jupyter
如果还依赖其他包,如sklearn,可以再tf2.0虚拟环境中进行安装。
(tf2.0) C:\Windows\system32>conda install scikit-learn
(?)号外
有资料介绍(CSDN:在jupyter中使用Tensorflow):需要安装python kernel for Tensroflow:
ipython kernelspec install-self --user
这个我没有进行安装,也不知道为什么要这么做。若有知道原因的,请告诉我。
CSDN:使用anaconda安装tensorflow (windows10环境)
简书:基于Anaconda 安装tensorflow
简书:在Jupyter中使用TensorFlow