当前位置:网站首页>Pytorch Foundation (I) -- anaconda and pytorch installation
Pytorch Foundation (I) -- anaconda and pytorch installation
2022-06-10 16:56:00 【Long way to go 2021】
PyTorch Installation , It's common Anaconda/miniconda+Pytorch+ (Pycharm/VS Code) Tools for , Our installation is divided into the following steps
1 Anaconda Installation
stay DL and ML in , A lot of mature package. Install one by one package so much trouble , And it is prone to strange problems . and Anaconda It solved our problem very well , It integrates common scientific analysis ( machine learning , Deep learning ) A large number of package. We have omitted to install some package The process of .
1.1 install Anaconda/miniconda
(1) land Anaconda | Individual Edition, Select the appropriate system DownLoad
(2) You can go to Tsinghua mirror to install the corresponding system ,Windows according to 64 Bits or 32 Bit download corresponds to .exe,Linux install .sh,Mac install .pkg. It is generally recommended not to choose the latest version ( Less stable ), Here, it is suggested to choose the... In the previous two years anaconda3 Any version .
Here we use Linux For example , Assume that the installation package has been downloaded , You can input commands directly at the terminal , First cd Go to the folder where you have this installation package ( The assumption is Documents)
cd Documents
Follow up bash + Installation package name ( Folder path name is OK )
bash "/home/carpediem/Downloads/Anaconda3-5.3.1-Linux-x86_64.sh"
For detailed installation steps, please refer to the installation tutorial of each system :
- Anaconda Super detailed installation tutorial (Windows In the environment ):https://blog.csdn.net/fan18317517352/article/details/123035625
- stay Linux Installation on server Anaconda( Hyperdetail ):https://blog.csdn.net/wyf2017/article/details/118676765
- Mac Installation on Anaconda Most comprehensive tutorial :https://zhuanlan.zhihu.com/p/350828057
1.2 Verify successful installation
Windows Find... On the start page Anaconda Prompt, Generally in Anaconda3 Under folder ,Linux Input... At the terminal anaconda You can verify ,
No command found after input , Probably because the environment variables have not been configured yet . Enter the following command :
vim ~/.bashrc
Add... On the last line after entering , among username Is your account name , Here according to your own installation Anacona To modify the path of :
export PATH=/home/username/anaconda3/bin:$PATH
Update the configuration file after adding
source ~/.bashrc
Re input anaconda, You can verify whether the installation is successful .
1.3 Creating a virtual environment
Linux At terminal (Ctrl+Alt+T) Conduct ,Windows stay Anaconda Prompt Conduct
View existing virtual environments
conv info --env
conda env list

1. Creating a virtual environment
In deep learning and machine learning , We often create different versions of virtual environments to meet some of our needs . Let's introduce the commands for creating a virtual environment . In the choice Python version , Don't choose too high , Suggested choice 3.6-3.8, Too high a version will cause the related libraries to be inapplicable .
conda create -n env_name python==version
2. Delete virtual environment command
conda remove -n env_name --all
3. Activate the environment command
conda activate env_name
4. Exit the current environment
conda deactivate
1.4 Source change
In the installation package when , We often use pip install package_name and conda install package_name The order of , But some package Download will be slow , So we need to change the source , Switch to domestic sources , Speed up our downloads . The following is the source switching of the two corresponding methods
1.4.1 pip Source change
1. Linux
Linux Source change under , First, we need to create a new folder under the user directory .pip, And create a new file in the folder pip.conf, The specific command is as follows
cd ~
mkdir .pip/
vi pip.conf
And then , We need to be in pip.conf Add the following :
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
2. Windows
- File manager file path address bar :
%APPDATA%enter , Quick to enterC:\Users\ Computer users \AppData\RoamingIn the folder ; - newly build pip Folder and create a new one in the folder
pip.iniThe configuration file ; - We need to be in
pip.iniProfile contents , We can choose to use Notepad to open , Enter the following , And press ctrl+s preservation , Here we use watercress as an example .
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
Common image installation source websites
(1) Alibaba cloud http://mirrors.aliyun.com/pypi/simple/
(2) douban http://pypi.douban.com/simple/
(3) Chinese academy of sciences http://pypi.mirrors.opencas.cn/simple/
(4) Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/
(5) University of science and technology of China http://pypi.mirrors.ustc.edu.cn/simple/
(6) Huazhong University of science and technology http://pypi.hustunique.com/
(7)Python official https://pypi.python.org/simple/
(8)v2ex http://pypi.v2ex.com/simple/
1.4.2 conda Source change
- ( Tsinghua source ) Official source change help
- Aliyuan , You can refer to : Alibaba cloud image
(1) View source
conda config --show-sources
(2) Switch source
conda config --add channels XXXX
conda config --set show_channel_urls yes
(3) Delete source
conda config --remove channels XXX
(4) Switch back to the source
conda config --remove-key channels
1. Windows System
TUNA Provides Anaconda The image of the warehouse and the third-party source , Each system can modify the user directory .condarc file .Windows The user cannot directly create a file named .condarc The file of , You can do it first conda config --set show_channel_urls yes After generating the file, modify .
When this is done , We need to change C:\Users\User_name\.condarc This file , Delete the original contents in the file after opening , Copy the following and save it .
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
After this step is completed , We need to open it Anaconda Prompt function conda clean -i Clear index cache , Make sure you use the index provided by the mirror station .
2. Linux System
stay Linux Under the system , Directly enter the following command at the terminal
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
We still need to revise it .condarc To carry out
cd ~
vi .condarc
stay vim Next , We need to type i Enter edit mode , Paste the content above , Press ESC Exit edit mode , Input :wq Save and exit .
We can go through conda config --show default_channels Check whether the source change is successful . meanwhile , We still need conda clean -i Clear index cache , Make sure you use the index provided by the mirror station . If the source does not take effect , Try to .condarc In the document - defaults Remove that line
2 Check for NVIDIA GPU
If this part only has CPU Or the small partners of centralized display can skip this part .
- windows
We can pass incmd/terminal inInputnvidia-smi(Linux and Win command )、 Use NVIDIA Control panel and use task manager to check whether you have NVIDIA Independent graphics card and its model


- linux

We need to look at the version number , See what you can be compatible with CUDA edition , Later installation PyTorch Is downward compatible . The specific adaptation table is shown in the figure below .
3 PyTorch Installation
Step 1: Sign in PyTorch Official website

Step 2:Install

In this interface, we can choose to start locally (Start Locally), Development of cloud (Cloud Partners), Former Pytorch edition (Previous PyTorch Versions), Mobile development (Mobile), Here we need to install locally .
Step 3: Choose the command
We need to choose the command according to our own situation and copy it , And then use conda Download or pip download ( Suggest conda install )
open Terminal, Input conda activate env_name, Activate the environment and switch to the environment , We can do it PyTorch Installed.

notes :
Stable Represents a stable version ,Preview Represents the previous version
It can be combined with whether the computer has a graphics card , choice CPU Version or CUDA edition , The suggestion still needs NVIDIA GPU
We are officially advised to use Anaconda To manage
System requirements for installation
- Windows:
- Windows 7 And higher ; It is recommended to use Windows 10 Or even higher
- Windows Server 2008 r2 And higher
- Linux: With the common CentOS and Ubuntu For example
- CentOS, Minimum version 7.3-1611
- Ubuntu, Minimum version 13.04, This will lead to cuda The maximum version installed is different
- macOS:
- macOS 10.10 And above
- Windows:
Some computers support cuda edition <10.2, At this point, we need to manually downgrade , That is cudatoolkit = The version you fit , But here we need to pay attention to keep Pytorch and cudatoolkit Version adaptation for . see Previous PyTorch Versions | PyTorch
Step 4: Download Online
If we use Anaconda Prompt For downloading , We need to get through conda activate env_name, Activate our virtual environment to , Reenter command .
notes : We need to download the following instructions -c pytorch Remove to ensure the use of Tsinghua source download , Otherwise, it will be downloaded from the official website by default .
Step 5: Download offline
Windows
During the installation , We may have some strange problems , This leads to unsuccessful online downloading , We can also use Download offline Method .
Download address :https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
Download the address above , We need to download the corresponding version pytorch and torchvision package , Then open the Anaconda Prompt/Terminal in , Enter the installation path .
cd package_location
conda activate env_name
Next, enter the following command to install the two packages
conda install --offline pytorch The full name of the compressed package ( Suffixes should not be forgotten )
conda install --offline torchvision The full name of the compressed package ( Suffixes should not be forgotten )
Step 6: Verify successful installation
Enter the A virtual environment , And then enter python, Enter the following code .
import torch
torch.cuda.is_available()
This command means to verify that you can call cuda, If we Installation is CPU Version will return False, To be able to call GPU Will return True. Generally, if this command does not report an error, it will prove that the installation is successful .
Reference resources
- PyTorch Installation :https://github.com/datawhalechina/thorough-pytorch/blob/main/source/
- Use Tsinghua 、 Alibaba and other image sources have improved pytorch Installation success rate :https://blog.csdn.net/Robin_Pi/article/details/107538672
边栏推荐
- VBA judge whether the file exists and ask for the idea of file backup
- 从零开始,如何拥有自己的博客网站【华为云至简致远】
- Investment prospect and development strategy planning of China's waste power generation equipment industry 2022-2028 Edition
- Postman common assertions
- Carry forward the past and forge ahead into the future, multiple residuals | densenet (I)
- NumPy 学习笔记
- MM主要的表和主要字段_SAP刘梦_
- 靠,嘉立创打板又降价
- Check whether there is a QR code in the picture
- Effect comparison and code implementation of three time series hybrid modeling methods
猜你喜欢

This paper introduces three feature selection methods in machine learning

Live broadcast preview | a new era of social interaction, exploring new social experiences in the universe

Link multiple alamofire requests - chain multiple alamofire requests

NumPy 学习笔记

Mm main tables and main fields_ SAP LIUMENG_
sql注入报错之注入原理实例解析

线程面试相关问题

Li Ling: in six years, how did I go from open source Xiaobai to Apache top project PMC

What is the 100th trillion digit of PI decimal point? Google gives the answer with Debian server

Technology sharing | quick intercom, global intercom
随机推荐
CAP 6.1 版本发布通告
Swift read userinfo of remote notification
圆周率 π 小数点第 100 万亿数字是多少?Google 用 Debian 服务器给出了答案
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程,进互联大厂如此简单
Mm main tables and main fields_ SAP LIUMENG_
Quickly understand the commonly used symmetric encryption algorithm, and no longer have to worry about the interviewer's thorough inquiry
Docker安装Redis镜像详细步骤(简单易懂,适合新手快速上手)
Financial risk control practice - anomaly detection (I)
简单实现文件上传
VBA判断文件是否存在及问文件备份思路
Fiddler创建AutoResponder
The guide to the application of all-in-one privacy computing machine - the technical requirements for financial application of all-in-one privacy computing machine was officially released to help the
postman参数化
Li Ling: in six years, how did I go from open source Xiaobai to Apache top project PMC
Basic use of pycharm
VBA将字符串分割、存入数组、写入文件并保存
Global and Chinese intelligent elderly care system industry 2 competition analysis and Investment Strategic Planning Research Report 022-2028
MM主要的表和主要字段_SAP刘梦_
Zhangxiaobai teaches you how to use Ogg to synchronize Oracle 19C data with MySQL 5.7 (1)
L1-069 tire pressure monitoring (15 points)