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


Posted in Python onApril 16, 2020

1、更新NVIDIA驱动 

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

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

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

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

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

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

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

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

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

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

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

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

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

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虚拟环境步骤整理的文章就介绍到这了,更多相关Anaconda pytorch-gpu虚拟环境内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
python调用shell的方法
Nov 20 Python
Python实例之wxpython中Frame使用方法
Jun 09 Python
Python中的字符串类型基本知识学习教程
Feb 04 Python
Python实现PS滤镜功能之波浪特效示例
Jan 26 Python
python对象与json相互转换的方法
May 07 Python
python输出带颜色字体实例方法
Sep 01 Python
你还在@微信官方?聊聊Python生成你想要的微信头像
Sep 25 Python
python Jupyter运行时间实例过程解析
Dec 13 Python
Python3直接爬取图片URL并保存示例
Dec 18 Python
如何用Anaconda搭建虚拟环境并创建Django项目
Aug 02 Python
python字典按照value排序方法
Dec 28 Python
Python实现学生管理系统(面向对象版)
Jun 24 Python
解决paramiko执行命令超时的问题
Apr 16 #Python
python nohup 实现远程运行不宕机操作
Apr 16 #Python
通过python 执行 nohup 不生效的解决
Apr 16 #Python
在python中使用nohup命令说明
Apr 16 #Python
VS2019+python3.7+opencv4.1+tensorflow1.13配置详解
Apr 16 #Python
python实现程序重启和系统重启方式
Apr 16 #Python
Mac PyCharm中的.gitignore 安装设置教程
Apr 16 #Python
You might like
PHP自动更新新闻DIY
2006/10/09 PHP
Laravel 5框架学习之表单验证
2015/04/08 PHP
浅析php设计模式之数据对象映射模式
2016/03/03 PHP
保证JavaScript和Asp、Php等后端程序间传值编码统一
2009/04/17 Javascript
jQuery1.6 类型判断实现代码
2011/09/01 Javascript
jQuery EasyUI API 中文文档 - TimeSpinner时间微调器
2011/10/23 Javascript
javascript如何动态加载表格与动态添加表格行
2013/11/27 Javascript
jQuery获取当前对象标签名称的方法
2014/02/07 Javascript
jquery跟js初始化加载的多种方法及区别介绍
2014/04/02 Javascript
JS实现可展开折叠层的鼠标拖曳效果
2015/10/09 Javascript
JQuery统计input和textarea文字输入数量(代码分享)
2016/12/29 Javascript
详解Vue iview IE浏览器不兼容报错(Iview Bable polyfill)
2019/01/07 Javascript
js最实用string(字符串)类型的使用及截取与拼接详解
2019/04/26 Javascript
vue父组件触发事件改变子组件的值的方法实例详解
2019/05/07 Javascript
vue 实现v-for循环回来的数据动态绑定id
2019/11/07 Javascript
[20:30]职业巡回赛回顾
2018/08/09 DOTA
caffe binaryproto 与 npy相互转换的实例讲解
2018/07/09 Python
Python实现的拉格朗日插值法示例
2019/01/08 Python
python学生管理系统
2019/01/30 Python
Python3标准库总结
2019/02/19 Python
在win10和linux上分别安装Python虚拟环境的方法步骤
2019/05/09 Python
Python reversed函数及使用方法解析
2020/03/17 Python
卸载tensorflow-cpu重装tensorflow-gpu操作
2020/06/23 Python
Python开发.exe小工具的详细步骤
2021/01/27 Python
CSS3 创建网页动画实现弹跳球动效果
2018/10/30 HTML / CSS
英国豪华真皮和布艺沙发销售网站:Darlings of Chelsea
2018/01/05 全球购物
上海某公司.net方向笔试题
2014/09/14 面试题
广州迈达威.net面试题目
2012/03/10 面试题
Shell如何接收变量输入
2012/09/24 面试题
大学生写自荐信的技巧
2014/01/08 职场文书
投资协议书范本
2014/04/21 职场文书
2014年反洗钱工作总结
2014/11/22 职场文书
食品质检员岗位职责
2015/04/08 职场文书
党员志愿者服务倡议书
2015/04/29 职场文书
2016年清明节红领巾广播稿
2015/12/17 职场文书
标准版个人借条怎么写?以及什么是借条?
2019/08/28 职场文书