• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

python 搞代码 4年前 (2022-01-07) 22次浏览 已收录 0个评论

这篇文章主要介绍了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

来源gaodai.ma#com搞##代!^码网

–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虚拟环境内容请搜索gaodaima搞代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持gaodaima搞代码网

以上就是Anaconda配置pytorch-gpu虚拟环境的图文教程的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Anaconda配置pytorch-gpu虚拟环境的图文教程

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址