当前位置:网站首页>PyTorch installation - error when building a virtual environment in conda before installing PyTorch
PyTorch installation - error when building a virtual environment in conda before installing PyTorch
2022-08-03 03:31:00 【Top Secret】
目录
2.Error when building a virtual environment:
5.安装pytorch(这里安装的是CPU版的,There is one laterCUDA版的)
7.exit()退出编辑,and close the virtual environment
1.查看condaAll virtual environments in
2.Activate into any of these virtual environments
参考文章:
PyTorch 最新安装教程(2021-07-27)_ZSYL的博客-CSDN博客_pytorch 镜像安装
一. Anacoda建立虚拟环境
1.打开Anaconda的Prompt

2.Error when building a virtual environment:
注意:此处的“pytorch”is the name of the virtual environment,Of course, other names are also possible.pythonThe specified version to be used withAnaconda的相匹配;

conda create -n pytorch python=3.7

出现以下的原因就是你当前设定的镜像源已经不支持该包了,所以需要重新设定.
2.1 错误的解决办法
使用以下命令恢复默认源:
conda config --remove-key channels然后再次执行:
conda create -n pytorch python=3.7

3. 查看环境是否安装成功
conda info --envs
可以看到包含base和pytorch两个环境(*Indicates the current environment).
4. 进入创建的pytorch环境(激活环境)
conda activate pytorch5.安装pytorch(这里安装的是CPU版的,There is one laterCUDA版的)
注意:It is recommended to create virtual environments separately,一个(pytorch)用来下载CPU版的PyTorch,另一个(PyTorch)用下载GPU的cuda版的PyTorch.
根据自己的安装版本,在Pytorch官网寻找安装命令代码:
Pytorch官网:PyTorch
将复制的代码粘贴到命令行格式下,弹出提示,输入 y,即可完成安装:
(此处选择的CPU版本)
Then in Chuangjiepytorch的虚拟环境下运行代码即可:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
6. 测试pytorch
(1)进入python:python
(2)测试pytorch:import torch
conda activate pytorch
import torch
import torch vision
print(torch.__version__) # pytorch版本
print(torch.version.cuda) # cuda版本 返回的是GPU版
print(torch.cuda.is_available()) # 查看cuda是否可用

7.exit()退出编辑,and close the virtual environment
conda deactivate
二.使用Anaconda创建的pytorch虚拟环境
Refer to the following articles for the following content,如侵权,联系删除:
(2条消息) PyTorch 最新安装教程(2021-07-27)_ZSYL的博客-CSDN博客_pytorch安装教程
1.查看condaAll virtual environments in
(base) C:\Users\Naruto>conda info --envs2.Activate into any of these virtual environments
(base) C:\Users\Naruto>conda activate pytorch具体如下:

3. 配置清华TUNA镜像源
TUNA 提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch等,查看完整列表)的镜像,各系统都可以通过修改用户目录下的 .condarc 文件.Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改.
注:由于更新过快难以同步,TUNA不同步
pytorch-nightly, pytorch-nightly-cpu, ignite-nightly这三个包.
3.1 生成 .condarc 文件
在 Anaconda prompt 命令窗口,中输入:
(pytorch) C:\Users\Naruto>conda config --set show_channel_urls yes之后可以在 C:\Users\xxx 中看到 .condarc 文件 :

3.2 记事本打开 .condarc 文件,重写其中的内容
即复制,粘贴如下内容:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
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

This can be added Anaconda Python Free warehouse.
3.3 清除索引缓存
在Anaconda prompt 命令窗口运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引.

3.4 安装cuda版的PyTorch
进入pytorch官网:PyTorch
网页下拉,即可看到下图,官网会自动根据你的电脑,显示的即是你可安装的CUDA版本,并给出安装命令.
查看电脑的cuda版本:
(base) C:\Users\Naruto>nvidia-smi
复制命令:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch或者:

复制语句:
conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge打开 Anaconda prompt 命令窗口,Enter the created virtual environment to download:

(cudais not installed,后续再试试)
4.Simple application overview

接着看这里:
(2条消息) PyTorch 最新安装教程(2021-07-27)_ZSYL的博客-CSDN博客_pytorch安装教程
三.Pychram使用PyTorch的方法
1.添加环境

然并卵,

通过Anaconda创建自己的环境,并且安装torch、torchvision等包,在Anaconda promptIt can be imported normally in the command window,而在PyCharmThe compiler will report an error.通过 activate PyTorch Create your own pytorch 环境中,输入pythonenvironment will be displayedpython的版本信息,再依次import,Obviously no error.
这是因为在Anaconda的环境下有支持 import torch 的 dll,而在PyCharm中使用的是你创建的新环境,还缺少相应支持的dll,你仅需在PyCharm中配置环境变量.(Refer to the original article)
2.Solve:配置环境变量


D:\Anaconda3;
D:\Anaconda3\Library\mingw-w64\bin;
D:\Anaconda3\Library;
D:\Anaconda3\Lib\site-packages;
D:\Anaconda3\Scripts;
D:\Anaconda3\envs\pytorch\Library\bin;
即:
D:\Anaconda3;D:\Anaconda3\Library\mingw-w64\bin;D:\Anaconda3\Library;D:\Anaconda3\Lib\site-packages;D:\Anaconda3\Scripts;D:\Anaconda3\envs\pytorch\Library\bin;

没装上CUDA的版本,Special thanks to the authors of the above reference articles!!!
边栏推荐
- [@property enhancement in Objective-C language]
- 【云原生】阿里云ARMS业务实时监控
- 370万欧元!西班牙iPronics加速可重构光子芯片商用
- vant-field中colon属性为true报错
- 15【背景 渐变色】
- 问题记录:jenkins构建时报错The goal you specified requires a project to execute but there is no POM in...
- 【Objective-C语言中的@property增强】
- 【GO记录】从零开始GO语言——用GO语言做一个示波器(二)基于arduino的简易示波器
- JWT入门学习
- [Static type and dynamic type compile check and run check in Objective-C]
猜你喜欢

How does Excel compare if two columns of strings are the same?

# RACE32——高级断点的设置和应用

C语言——-动态内存开辟与管理(malloc,free,calloc,realloc)+柔性数组

Sentinel vs Hystrix 限流对比,到底怎么选?

【数据分析】基于MATLAB实现SVDD决策边界可视化

Excel 如何比较两列字符串是否相同?

Jenkins2.328+sonarqube7.9 实现代码自动化检测

Fiddler基本使用

Wei Dongshan Digital Photo Frame Project Learning (5) Transplantation of libjpeg-turbo

MySQL-如何分库分表?一看就懂
随机推荐
# RACE32——高级断点的设置和应用
一次偶然的钓鱼文件分析
C语言——结构体(声明、内存对齐、自引用)、位段、联合体、枚举常量合集
Useful Monitoring Scripts What you want part1 in Oracle
15【背景 渐变色】
Scala基础【异常、隐式转换、泛型】
实现统一账号登录,sonarqube集成ldap
Topic Modeling of Short Texts: A Pseudo-Document View
vant-field中colon属性为true报错
金仓数据库 Pro*C 迁移指南( 5. 程序开发示例)
为什么要使用 playwright 做浏览器自动化测试?
流程图(1)
程序员写代码日常 | 每日趣闻
基于 Cyclone IV 在 Quartus 中配置 IP 核中的 PLL、RAM 与 FIFO 的详细步骤及仿真验证
05-分布式计算框架
智能健身动作识别:PP-TinyPose打造AI虚拟健身教练!
MySQL-多表查询
密码学的基础:X.690和对应的BER CER DER编码
Auto.js Pro 计算脚本运行时间
记录学习--Navicat使用自定义数据库列表
