reference:
https://www.bilibili.com/video/BV1Fx4y1j7yy/?spm_id_from=333.337.search-card.all.click
The linux environment is often used in deep learning, but compared to windows, for a novice like the author, using linux is definitely not the first choice, but some packages have been used recently, which can only be used in the linux environment. When installing dual systems , I found WSL2, tried it and it works very well, so record the installation tutorial, if you are not used to linux, you can try it.
Install WSL and Ubuntu
The online tutorial has a lot of commands when installing WSL. I accidentally found from bilibili that it is very useful to use the Microsoft Store to download the UP master, so this article also uses this method. The video link is listed in the top reference. At present, the latest version is WSL2, which is the default version when using the win11 system. If it is win10, you may need to install WSL2 in other ways.
1. Enable some functions of windows
First enter hyper in the search bar below windows
Click to enter, tick the three items in the box, click OK, wait for the configuration to complete and restart the computer.
2. Install WSL and Ubuntu
Open the Microsoft store and search for WSL and Ubuntu, click Install
After the installation is complete, open Ubuntu
Configure Ubuntu user information:
Then wait for a while, as shown in the figure below, the configuration is successful
Then open a terminal (Powershell):
Enter the following command to see the installed version:
wsl -l --all -v
3. Migrate to another disk
By default, WSL and Ubuntu will be installed on the C drive. This section is to transfer these two parts of the C drive to other drives. You can skip this section if you don’t need it.
When we enter the wsl -l --all -v command, if Ubuntu's STATE is Running, first enter the following command to suspend it:
wsl --shutdown
First go to the disk to be transferred to create a new folder, as shown in the figure, I want to transfer to the F:\linux\Ubuntu location
Go back to the terminal and enter the command:
wsl --export Ubuntu-22.04(根据自己版本填写) 转移的位置+\名称.tar
As shown in the figure, the export is successful:
Next, log out of the current version of the C drive:
wsl --unregister 名称
After successful logout, re-import WSL and install it on the target disk:
wsl --import 版本 导入位置 第一步tar包的位置 --version 2
It may not be easy to understand. At this time, my command is:
wsl --import Ubuntu-22.04 F:\linux\Ubuntu F:\linux\Ubuntu\Ubuntu-22.04.tar --version 2
The effect is as shown in the figure:
The import is successful, we can manually delete the tar package in the import location:
Then enter WSL in the terminal:
At this point the user is root, not a user created by ourselves, we can set the default user
First enter exit to return to the terminal, and then enter the following command:
名称 config --default-user 用户
Notice! For the "name" part of this command, enter the first few letters and press the Tab key to complete automatically!
It can be seen that the name has changed, so it needs to be automatically completed, so that there will be no problems. After setting, click the terminal drop-down icon to choose to enter Ubuntu
So far WSL and Ubuntu have been installed, the next chapter is to configure Pytorch in WSL Ubuntu
Install CUDA
WSL and windows common graphics driver
1. Open the NVIDIA Control Panel
Before installing CUDA, confirm what version of CUDA the computer can install
As shown in the figure, the machine can install up to CUDA 12.2 version
2. Download CUDA
Go to the CUDA download page
https://developer.nvidia.com/cuda-toolkit-archive
Select the CUDA version to download, it cannot exceed the highest installable version, I choose CUDA11.7.1,
Click to enter, install the system selection
A total of five items, and then drop down the page to see the installation command
Enter them one by one into the Ubuntu terminal:
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda-repo-wsl-ubuntu-11-7-local_11.7.1-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-7-local_11.7.1-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
As shown in the figure, there are a total of seven commands, so instead of taking screenshots one by one, copy them all in and wait for the installation to complete:
The process may be a bit slow, just wait
3. Configure environment variables
Enter the following command in the terminal:
sudo nano ~/.bashrc
Fill in the following to the end:
export PATH=/usr/local/cuda-11.7(安装的版本)/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.7(安装的版本)/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Note: CUDA11.7.1 is installed, but it is written to 11.7 when configuring environment variables
Press Ctrl+X to save and exit, then update the environment variables:
source ~/.bashrc
Execute the following command to check whether CUDA is installed successfully, as shown in the figure, the installation is successful:
Install cuDNN
cuDNN is not required to be installed, and I made more mistakes after installing according to various tutorials, so I will not demonstrate how to install cuDNN here. If the installation partner has a good method and there is no error after installation, you can communicate with us!
Note: Not installing cuDNN has almost no impact (I think)
Install Anaconda
First enter the Anaconda official website
https://www.anaconda.com/download
Select the little penguin on the right
Go to the image below, right click and select copy link
Go back to the terminal and execute:
wget+链接
Just wait for the installation to complete
Execute after successful installation:
sh Anaconda3-2023.03-1-Linux-x86_64.sh
Enter sh An and press the Tab key to automatically complete the following content
Then keep pressing Enter until you finally enter yes
Prompt that Anaconda will be installed in the /home/user folder, click the Enter key again, and wait for the installation to end
The following picture appears, the installation is successful
After the installation is complete, it is recommended to re-enter the UBuntu terminal, because it is prone to errors and the conda command cannot be found
When we re-entered, we found that it was preceded by (base)
Install the virtual environment
Under Windows, we also install pytorch in a virtual environment, because when an error occurs, just delete the virtual environment and reinstall it
Enter the following command:
conda create --name 虚拟环境名字 python=版本
Wait for the installation to complete and activate the virtual environment we created
conda activate 虚拟环境名字
In this way, we have entered the newly created virtual environment, and then installed Pytorch in the virtual environment
Install Pytorch
Enter the Pytorch homepage, if it is too slow, you can install the domestic mirror
https://pytorch.org/get-started/previous-versions/
Find the Pytorch version command corresponding to the CUDA version we installed
Copy the command to the Ubuntu terminal and paste it to install:
After starting the installation, all we can do is wait...
After the installation is complete, you can exit the terminal, and you can configure WSL to use in Pycharm
Pycharm configures WSL
Note: Pycharm Professional Edition must be used
In the compiler in the lower right corner of Pycharm, select as shown in the figure
After the system installs WSL, it will automatically detect
Wait for the display to be successful and click Next
Next select Virtualenv Environment, select Existing in Environment
Then choose the following path
\wsl$\Ubuntu-22.04\home\user (user set when installing Ubuntu) \anaconda3\envs\pytorch_env (virtual environment created by yourself)\bin\python3
Wait for Pycharm to respond, after the response is completed, it can be verified
Open the Terminal terminal in Pychram and enter wsl
As shown in the picture, we have entered the Linux system, and the installation is successful!
Flowers are over~