Anaconda配置pytorch-gpu虚拟环境的图文教程

所属分类: 脚本专栏 / python 阅读数: 1700
收藏 0 赞 0 分享

1、更新NVIDIA驱动 

选对应自己显卡的驱动,(选studio版本,不要game版本)驱动链接 

2、添加Anaconda清华镜像

方法一:anaconda命令替换

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
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

(Mark)换回默认源代码:

conda config --remove-key channels

方法二:替换.condarc

show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
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

3.创建虚拟环境

创建:
conda create -n 环境名 python=X.X
开启:
activate 环境名
关闭:
conda deactivate
删除:
conda remove -n 环境名 --all
添加包:
conda install -n 环境名 包名
移除包:
conda remove -n 环境名 包名

4. 安装pytorch命令——对应情况自选:命令代码链接(pytorch官网)

1.PIP安装(推荐)

pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

这个速度比conda稳定 卡住了按回车好像还可以救回来

2.conda安装(不推荐 老是中断)

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch (要去掉-c pytorch 不然还是默认源)
最终输入命令:
conda install pytorch torchvision cudatoolkit=10.1

网络在各处中断 有时候48%又断了

5.PIP安装完之后测试

import torch
flag = torch.cuda.is_available()
print(flag)
 
ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())

结果:被conda命令折腾一下午,终于被pip命令解救了!

更多精彩内容其他人还在看

python中seaborn包常用图形使用详解

今天小编就为大家分享一篇python中seaborn包常用图形使用详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

numpy:找到指定元素的索引示例

今天小编就为大家分享一篇numpy:找到指定元素的索引示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

python实现图片上添加图片

这篇文章主要为大家详细介绍了python实现图片上添加图片,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

从numpy数组中取出满足条件的元素示例

今天小编就为大家分享一篇从numpy数组中取出满足条件的元素示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Python实现图片添加文字

这篇文章主要为大家详细介绍了Python实现图片添加文字,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

python实现在多维数组中挑选符合条件的全部元素

今天小编就为大家分享一篇python实现在多维数组中挑选符合条件的全部元素,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Python如何使用BeautifulSoup爬取网页信息

这篇文章主要介绍了Python如何使用BeautifulSoup爬取网页信息,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
收藏 0 赞 0 分享

浅谈python已知元素,获取元素索引(numpy,pandas)

今天小编就为大家分享一篇浅谈python已知元素,获取元素索引(numpy,pandas),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

numpy ndarray 按条件筛选数组,关联筛选的例子

今天小编就为大家分享一篇numpy ndarray 按条件筛选数组,关联筛选的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Python pickle模块实现对象序列化

这篇文章主要介绍了Python pickle模块实现对象序列化,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多