conda安装tensorflow(python)

1. 版本

CPU/GPU、CUDA、python、tensorflow版本尽量使用以下配置,参考下面图片或网址:

在 Windows 环境中从源代码构建  |  TensorFlow (google.cn)

 查看显卡支持的cuda版本:

查看显卡GPU支持的CUDA版本,和对应版本tensorflow - 简书 (jianshu.com)

 如上图就是支持CUDA11(及以下)

2. 安装(通过conda)

安装所需命令来自于MOOC北京大学tensorflow课程:人工智能实践:Tensorflow笔记_中国大学MOOC(慕课) (icourse163.org)

2.1 安装anaconda

官网:Anaconda | The World's Most Popular Data Science Platform,选择不同版本的工具会自动安装其对应版本的python,如果已经安装过python环境选择保留或卸载没什么影响。

至于什么是anaconda和安装细节,自己搜,或者移步至:Anaconda的安装和详细介绍(带图文) - 代码帮 - 博客园 (cnblogs.com)

(推荐安装过程选中添加环境变量)


以下过程中选择的版本应结合自己需要以及上面的图表。


 conda安装完成后,打开这个,开始后续操作

2.2 安装cuda和cudnn

以下非必须,只是个人需要,所以做了记录。如果不需要或者下面安装语句报错了,可能是需要换一个国内的镜像(镜像问题看后续)或者电脑硬件不支持,可以跳过直接安装tensorflow。

(1)新建一个python环境

conda create -n TF2.4 python=3.8

其中TF2.4是自己起名,随意;python的版本应与自己电脑上的保持一致(或者不一致让它再下个?)。成功的话会让你选择是否执行,键入y即可

(2)进入新建的环境并安装英伟达的SDK

conda activate TF2.4
conda install cudatoolkit=11.0

(3)安装英伟达深度学习软件包

conda install cudnn=8.0

2.3 安装tensorflow

pip install tensorflow==2.4

如果看到下图,那么恭喜你,基本成功了

 2.4 验证及查看安装版本

依次键入以下语句:

python
import tensorflow as tf
tf.__version__

3. 安装过程中遇到的错误

3.1 HTTP error occurred...

解决:更改镜像或者再试一次(真的会有用)

使用国内镜像参考:(1条消息) Anaconda An HTTP error occurred when trying to retrieve this URL.HTTP errors are often intermittent_whocare的博客-CSDN博客

3.2 The channel is not accessible or is invalid. 

使用国内镜像后报错:The channel is not accessible or is invalid. 

解决:

换别的镜像或者恢复默认源(就是切回原来的境外url,多试几次会成功的)

(1)换别的镜像

anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror(这也是我报错终结的地方)

(1条消息) Conda配置国内镜像源_taoyu94的博客-CSDN博客_conda镜像源

在“3.1”中的两条命令会生成这么个文件,打开并编辑内容为:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

然后再次执行“install”命令

(2)恢复默认源

Anaconda创建虚拟环境报错—UnavailableInvalidChannel: The channel is not accessible or is invalid - 灰信网(软件开发博客聚合) (freesion.com)

3.3 PackagesNotFoundError: The following packages are not available from current channels

解决:

conda config --add channels conda-forge

4. 完成

安装完成,现在可以在pycharm中使用创建好的环境了!

 

 

posted @ 2021-07-13 14:33  YIYUYI  阅读(6256)  评论(0编辑  收藏  举报