第一步:创建虚拟环境,并激活
根据需要安装的tensorflow包版本,查找兼容的python版本
举例子,我需要安装的tensorflow包为1.9,符合的python环境为3.5-3.6
TensorFlow官网对照表
地址:在 Windows 环境中从源代码构建 | TensorFlow
# 根据需要的python版本,创建虚拟环境IMOFDM_030524
(base) C:\Users\78437>conda create -name IMOFDM_030524 python = 3.6
# 激活虚拟环境
(base) C:\Users\784377>activate IMOFDM_030524
第二步:安装tensorflow,并检查
选择清华源https://pypi.tuna.tsinghua.edu.cn/simple,可以加快安装速度
#虚拟环境中安装tensorflow1.9
(IMOFDM_030524) C:\Users\78437>pip install tensorflow==1.9 -i https://pypi.tuna.tsinghua.edu.cn/simple
进入python环境后导入tensorflow安装包
# 进入python环境
(IMOFDM_030524) C:\Users\78437>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.
# 导入tensorflow
>>> import tensorflow
# 退出python环境
>>> exit()
conda list 检查安装包目录(可以从中查找到python3.6.2,tensorflow1.9.0)
(IMOFDM_030524) C:\Users\78437>conda list
# packages in environment at C:\Users\78437\anaconda3\envs\IMOFDM_030524:
#
# Name Version Build Channel
absl-py 1.4.0 pypi_0 pypi
astor 0.8.1 pypi_0 pypi
certifi 2016.2.28 py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
dataclasses 0.8 pypi_0 pypi
gast 0.5.4 pypi_0 pypi
grpcio 1.48.2 pypi_0 pypi
importlib-metadata 4.8.3 pypi_0 pypi
markdown 3.3.7 pypi_0 pypi
numpy 1.19.5 pypi_0 pypi
pip 21.3.1 pypi_0 pypi
protobuf 3.19.6 pypi_0 pypi
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
six 1.16.0 pypi_0 pypi
tensorboard 1.9.0 pypi_0 pypi
tensorflow 1.9.0 pypi_0 pypi
termcolor 1.1.0 pypi_0 pypi
typing-extensions 4.1.1 pypi_0 pypi
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
werkzeug 2.0.3 pypi_0 pypi
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
zipp 3.6.0 pypi_0 pypi
参考链接:
在 Windows 环境中从源代码构建 | TensorFlow
https://blog.csdn.net/baidu_39157459/article/details/104109304