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

 更新时间:2020年04月16日 11:50:13   作者:星月㏇保洁  
这篇文章主要介绍了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 Tkinter创建GUI应用程序的示例

    Python Tkinter创建GUI应用程序的示例

    Tkinter提供了丰富的功能和灵活的接口,让开发者能够轻松地构建出各种各样的图形用户界面,本文介绍了使用Python的Tkinter库创建图形用户界面GUI应用程序,感兴趣的可以了解一下
    2024-12-12
  • 使用Python将Exception异常错误堆栈信息写入日志文件

    使用Python将Exception异常错误堆栈信息写入日志文件

    这篇文章主要介绍了使用Python将Exception异常错误堆栈信息写入日志文件,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-04-04
  • 数据可视化Pyecharts的实际使用方式

    数据可视化Pyecharts的实际使用方式

    这篇文章主要介绍了数据可视化Pyecharts的实际使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-04-04
  • 详解Python 循环嵌套

    详解Python 循环嵌套

    这篇文章主要介绍了Python 循环嵌套的相关资料,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-07-07
  • Python基础之函数嵌套知识总结

    Python基础之函数嵌套知识总结

    今天带大家回顾python基础知识,文中对Python函数嵌套作了非常详细的知识总结,对正在学习python基础的小伙伴们很有帮助,需要的朋友可以参考下
    2021-05-05
  • Scrapy爬虫Response子类在应用中的问题解析

    Scrapy爬虫Response子类在应用中的问题解析

    这篇文章主要为大家介绍了Scrapy爬虫Response它的子类(TextResponse、HtmlResponse、XmlResponse)在应用问题解析
    2023-05-05
  • python time.sleep()是睡眠线程还是进程

    python time.sleep()是睡眠线程还是进程

    这篇文章主要介绍了python time.sleep()是睡眠线程还是进程,通过实例代码给大家介绍了Python Sleep休眠函数 ,需要的朋友可以参考下
    2019-07-07
  • python3.x如何向mysql存储图片并显示

    python3.x如何向mysql存储图片并显示

    这篇文章主要介绍了python3.x如何向mysql存储图片并显示问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-03-03
  • pydantic进阶用法示例详解

    pydantic进阶用法示例详解

    这篇文章主要为大家介绍了pydantic进阶用法示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • pytorch 中的重要模块化接口nn.Module的使用

    pytorch 中的重要模块化接口nn.Module的使用

    这篇文章主要介绍了pytorch 中的重要模块化接口nn.Module的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-04-04

最新评论