使用conda准备tensorflow环境流程

发布时间 2023-08-13 18:56:15作者: white514

requirement.txt是这样写的:

tensorflow==2.10.1
pandas==1.3.5
numpy==1.21.6
scikit-learn==1.0.2
tqdm==4.64.1
absl-py==1.4.0
gdown==4.7.1

步骤如下

1 找到tensorflow对应python版本

访问官网 https://tensorflow.google.cn/install/source#tested_build_configurations ,将语言调为英文,上面显示了最新版本。可以看到:

所以,我应选择 python3.7-3.10、cudnn8.1、cuda11.2

2 在conda上创建新的python环境,并进入

比如命名为tf210,python版本选择3.8

conda create --prefix=D:\Anaconda3\envs\tf210 python=3.8
conda activate tf210

3 安装cuda cudnn

先查找cuda版本,版本选择11.2,点击链接下载下来

conda search cudatoolkit --info

再查找cudnn版本,选择8.1,点击链接下载下来

conda search cudnn --info

将下载下来的两个文件安装好

conda install --use-local 本地cuda包所在的路径
conda install --use-local 本地cudnn包所在的路径

4 安装gpu版本的tensorflow

执行这个命令conda install tensorflow==2.10.1,提示没有找到
于是使用 conda search tensorflow查看,发现镜像中只到2.10.0,确实没有2.10.1
尝试pip命令安装成功:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==2.10.1

接着安装全部的插件:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirement.txt

完成。