当前位置:网站首页>conda+pytorch环境教程
conda+pytorch环境教程
2022-07-26 18:10:00 【知道的都知道 不知道的慢慢了解】
conda+pytorch环境教程
前言
conda能管理不同的Python环境,不同的环境之间是互相隔离,互不影响的。以避免原本环境乱七八糟而导致错误。
即对原本环境的copy,是原本环境的副本。
在一台电脑上能够支撑多种环境。
conda是一个配置隔离python环境的工具
因为有些时候我们需要不同版本的python或不同版本的pip模块(比如你需要跑两个从github上下下来的代码,他们的tensorflow版本一个要求1.0一个要求2.0)
conda既可以实现pip模块不同版本共存,也可以实现python不同版本共存
conda只是一个工具,它有两种发行版,分别是Anaconda和Miniconda
anaconda是一个大而全的工具集合,包括了非常多常用的pip模块(如numpy、pandas、scipy、matplotlib等),它还有图形化的管理工具等
miniconda是一个单纯的conda工具,仅自带极少的python必要的包,干净纯粹,可以按照自己的需求构建任意环境
miniconda比anaconda小非常多,可以实现全部日常需求,只不过需要自己动手
默认conda会是base环境,你当然可以在这里装任何你需要的包,如果你想要创建多个隔离的虚拟环境,你还需要掌握conda环境的创建和切换。
一、新建conda环境
新建conda环境
conda create --name yolov5 python=3.9
name是新创建的虚拟环境的名字
python=3.9是python的版本号,可以指定版本。
查看现有的环境
conde info -e
我这里新建的环境名是yolov5
二、配置清华TUNA镜像源
1.生成.condarc文件
在 Anaconda prompt 命令窗口,中输入:
conda config --set show_channel_urls yes
之后可以在 C:\Users\xxx 中看到 .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
即可添加 Anaconda Python 免费仓库。
在Anaconda prompt 命令窗口运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引
三、安装pytorch
激活环境之后,就可以在环境中安装pytorch。进入pytorch官网选择PyTorch官网
网页下拉,即可看到下图,官网会自动根据你的电脑,显示的即是你可安装的CUDA版本,并给出安装命令
复制网页提供的命令
打开Anaconda prompt命令窗口,进入你刚刚创建的环境(我的环境名是yolov5)
conda activate yolov5
把从官网复制的那串很长的命令复制上去
下载过程会很费时间,并且网速要好
四、测试
打开 Anaconda prompt 命令窗口,激活环境,输入python,进入python开发环境中
输入下面命令
import torch
torch.cuda.is_available()
结果输出True 成功!!
五、conda命令
新建conda环境
conda create --name yourEnv python=3.9
yourEnv是新创建的虚拟环境的名字,创建完,可以装anaconda的目录下找到envs/yourEnv 目录
python=3.9:是python的版本号。也可以指定为【python=3.6】,若未指定,默认为是装anaconda时python的版本
若想要在创建环境同时安装python的一些包:
conda create -n yourEnv python=3.6 numpy pandas
激活conda环境
windows ==> activate yourEnv
linux/mac ==> source yourEnv
列出当前所有环境
conda info -e
或者
conda env list
查看当前环境的包和版本
conda list
特定环境所有包
conda list -n env_name
安装numpy sklearn包
conda install numpy scikit-learn
删除你的环境
conda env remove -n yourEnv --all
退出当前conda环境
conda deactivate
环境切换
conda activate YourEnvs
克隆虚拟环境
conda create -n newYourEnvs --clone oldYourEnvs
通过export命令导出环境配置 会生成一个.yml文件
conda env export > environment.yml
打开 environment.yml可以看见环境信息,下面的命令可以重新安装一个相同的环境
conda env create -f environment.yml
参考链接
边栏推荐
- Some time series modeling strategies (I)
- MySQL - multi table query and case explanation
- PMP practice once a day | don't get lost in the exam -7.26 (including agility + multiple choices)
- Introduction to Seata
- How far can Volvo, which has lost its "safety brand" due to declining sales and marginalization of its brand?
- 多线程学习笔记-1.CAS
- LeetCode笔记:Weekly Contest 303
- Article 7:exited on desktop-dff5kik with error code -1073741511
- MapReduce(二)
- Reentrantlock learning - lock release process
猜你喜欢

MySQL学习笔记-2.如何提高sql语句的查询性能

Sentinel isolation and degradation

This article explains in detail the five benefits that MES system brings to enterprises, with application scenarios

Microsoft silently donated $10000 to curl, which was not notified until half a year later

2022 welder (elementary) operation certificate examination question bank and simulation examination

Redis learning notes-2. Use of the client

篇7:exited on DESKTOP-DFF5KIK with error code -1073741511.

C#创建及读取DAT文件案例

MySQL日志介绍

Introduce the difference between @getmapping and @postmapping in detail
随机推荐
JS map usage
Is it safe for CSC qiniu members to open preferential accounts? I don't know if it's the lowest Commission
[swoole series 3.1] have you been asked about processes, threads, and collaborations during the interview?
How far can Volvo, which has lost its "safety brand" due to declining sales and marginalization of its brand?
配置服务器环境
MongoDB stats统计集合占用空间大小
Tensorflow-GPU 1.15安装
2022 chemical automation control instrument test question simulation test platform operation
立创EDA使用笔记
篇7:exited on DESKTOP-DFF5KIK with error code -1073741511.
密码一致,总显示如下图
高防服务器和高防IP的区别
时空预测5-GAT
MySQL日志介绍
Advanced template (runner's notes)
(ICLR-2022)TADA! Time adaptive convolution for video understanding
指标和标签是做什么的
Unity farm 2 - planting system
2022 Shanghai safety officer C certificate operation certificate examination question bank simulated examination platform operation
最后一篇博客