Anaconda配置pytorch-gpu虚拟环境的图文教程
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命令解救了!

总结
到此这篇关于Anaconda配置pytorch-gpu虚拟环境步骤整理的文章就介绍到这了,更多相关Anaconda pytorch-gpu虚拟环境内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
python+selenium 点击单选框-radio的实现方法
今天小编就为大家分享一篇python+selenium 点击单选框-radio的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2019-09-09
Python中的JSON Pickle Shelve模块特性与区别实例探究
在Python中,处理数据序列化和持久化是极其重要的,JSON、Pickle和Shelve是三种常用的模块,它们提供了不同的方法来处理数据的序列化和持久化,本文将深入研究这三个模块,探讨它们的特性、用法以及各自的优缺点2024-01-01
关于Python Selenium自动化导出新版WOS(web of science)检索结果的问题
这篇文章主要介绍了Python Selenium自动化导出新版WOS(web of science)检索结果,本代码属于半自动化导出,考虑到开发效率等因素,有两处在首次导出时需要手动操作,具体实现过程跟随小编一起看看吧2022-01-01


最新评论