当前位置:网站首页>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
边栏推荐
- Fosun Group hekaiduo: grow together with Alibaba cloud and help business innovation
- Print linked list from end to end (6)
- Basic use cases for jedis
- MFC basic knowledge and course design ideas
- Palm detection and finger counting based on OpenCV
- NumPy 学习笔记
- 隐私计算一体机的应用落地指南——《隐私计算一体机金融应用技术要求》正式发布,助力金融行业数据有序共享
- 互联网企业与芯片
- Research Report on development potential analysis and investment development strategy of global and Chinese hydraulic oil industry (2022-2028)
- Web2 到 Web3,意识形态也需要发生改变
猜你喜欢

象形动态图图像化表意数据

Swift read userinfo of remote notification

Bluetooth - Bluetooth SIG

Basic use cases for jedis

智慧景区视频监控 5G智慧灯杆网关组网综合杆

“禁塑令”下,中宝新材深挖可降解塑料,港交所买单吗?

卷起來,突破35歲焦慮,動畫演示CPU記錄函數調用過程,進互聯大廠如此簡單

Financial risk control practice - anomaly detection (I)

嵌入式开发:使用MCU进行无线更新面临的5大挑战
![ASP. Net core 6 framework unveiling example demonstration [12]: advanced usage of diagnostic trace](/img/29/72c04d86e48f9fa34e5e17c44b6bd9.jpg)
ASP. Net core 6 framework unveiling example demonstration [12]: advanced usage of diagnostic trace
随机推荐
Bluetooth - Bluetooth SIG
直播预告 | 社交新纪元,共探元宇宙社交新体验
看先进科技如何改变人类生活
MFC基础知识与课程设计思路
DAO 是如何实现去中心化治理的?
如何用Pygame制作简单的贪吃蛇游戏
VBA判断文件是否存在及问文件备份思路
解决idea打开某个项目卡住的问题
Embedded development: five challenges in wireless update using MCU
College entrance examination that year
You have a ml.net quick reference manual to check!
postman参数化
VBA判断一个长字符串中是否包含另一个短字符串
MFC basic knowledge and course design ideas
Li Ling: in six years, how did I go from open source Xiaobai to Apache top project PMC
Li Ling: in six years, how did I go from open source Xiaobai to Apache top project PMC
VBA divides strings, stores them in an array, writes them to a file, and saves them
Hidden Markov model and its training (1)
Why do I need a thread pool? What is pooling technology?
Financial risk control practice - anomaly detection (I)