anaconda环境下配置环境(tensorflow、pytorch)

1、查看Anaconda中的所有虚拟环境

conda info --envs


环境之间相互独立,可以在不同的环境中进行不同的配置
其中*标记的是当前正在使用的环境

2、查看、添加、删除Anaconda镜像

conda config --show channels

在这里插入图片描述

删除不使用的镜像:

conda config --remove channels 镜像名

命令添加新的镜像,如清华的镜像,下载速度会更快

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/
conda config --set show_channel_urls yes

conda config --set show_channel_urls yes的意思是从channel中安装包时显示channel的url,这样就可以知道包的安装来源了。

3、创建和移除Anaconda虚拟环境

创建一个名为tf2、Python版本为3.7.4的虚拟环境:

conda create --name tf2 python=3.7.4

移除虚拟环境,可以使用下面的命令:

conda remove -n tf2 --all

然后要使用conda activate tf2进行激活

安装不支持GPU的TensorFlow版本

pip install tensorflow     

安装支持GPU的TensorFlow版本

pip install tensorflow-gpu 

如果要升级TensorFlow,可以使用–upgrade命令行参数,命令如下:

pip install   --upgrade tensorflow    
pip install   --upgrade tensorflow-gpu

使用pip命令在国内同样面临下载缓慢的问题,所以可以使用-i命令行参数指定pip的国内镜像:

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

执行上面的命令会自动下载安装最新的TensorFlow版本,目前是TensorFlow2.x,也可以使用==进行指定版本

4、查看tensorflow版本

输入python后
然后输入:import tensorflow as tf

tf.__version__

出来tensorflow的版本信息

输入:tf.__path__

出来tensorflow的安装路径

5、安装pytorch

到pytorch的官网(https://pytorch.org/)查看不同版本的下载指令,我要下载0.4版本:

conda install pytorch=0.4.1 cuda90 -c pytorch

pytorch包大概有500M,可以看到下载速度非常慢,原因是该条命令中参数 -c pytorch表明官网的下载源优先级大于我们添加的下载源。
去掉后,使用清华源的镜像:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda install pytorch=0.4.1 cuda90

这样很快就可以安装好了

6、检查python和ipython环境

在我们的虚拟环境中安装完pytorch和tensorflow之后,需要检查一下python的路径是否正确,否则无法使用我们安装的软件包。
在这里插入图片描述
可以看到ipython的解释器路径还是默认的一个路径,并没有自动更改下来,所以我们要在该环境下重新安装一个ipython:
在这里插入图片描述
有时会出现一些包找不到的问题 Could not find a version that satisfies…
应该是源的问题,更改为豆瓣的源试试:

pip install ipython -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

–trusted-host pypi.douban.com 是为了获得ssl证书的认证

这样就能安装成功了,重新查看一下:
在这里插入图片描述

修改pip安装源加快python模块安装参考博客:
https://blog.csdn.net/u012592062/article/details/51966649

7. 安装pytorch时遇到error:conda.core.subdir_data.Response304ContentUnchanged

在这里插入图片描述

解决方法: 清除缓存

conda clean -i

解决问题
在这里插入图片描述
如果不行就清除含conda-forge的channel

conda config --remove channels conda-forge
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值