Deep learning environment configuration series articles (four): WSL2 configuration Windows11 and Linux dual system

Deep learning environment configuration series article directory

Chapter 1 Introduction to professional names and configuration schemes
Chapter 2 Anaconda configuration of Python and PyTorch
Chapter 3 Configuration of VS Code and Jupyter Python environment
Chapter 4 WSL2 configuration of Windows 11 and Linux dual systems
Chapter 5 Configuration of Docker deep learning development environment



foreword

WSL2 (Windows Subsystem for Linux 2) is a technology developed by Microsoft that allows users to run a Linux environment on a Windows system. It uses virtualization technology to provide better performance and compatibility. WSL2 supports common Linux distributions and can run native Linux applications directly. At the same time, it is integrated with Windows system and supports interoperability with Windows. This enables developers and system administrators to enjoy the convenience of Linux tools and development environments on Windows.


1. Detailed steps for Windows 11 to configure WSL2

1. Use the control panel to open the virtualization function

As shown in Figure 2-20

As shown in Figure 2-20, first search for "Control Panel" in the system, select "Programs", and then select "Enable or close Windows features".
Then turn on Windows virtualization, Linux subsystem (WSL2), Hyper-V.

Figure 2-20 Detailed steps for Windows 11 to configure WSL2

Note that some Windows 11 systems (especially the home version) do not have the function of Hyper-V, please refer to the next section for solutions. After the solution is completed, continue with the following operations.

2. Configure the environment with the command line

Open PowerShell as an administrator and enter the following commands respectively.

1.bcdedit /set hypervisorlaunchtype Auto    
2.Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All    
3.Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform #需要重启系统,请注意输入“y”并按“回车”建以重启    
4.Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

If the above content does not run smoothly, you can execute the following instructions.

1.dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart    
2.dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart    

3. Download the Linux sub-operating system

Open the Microsoft Store, and you can find a variety of different Linux operating systems, such as Debian, Ubuntu, Kali, etc. Simply enter the desired operating system name in the search box and select Download. As shown in Figure 2-21, the author chooses to use Ubuntu here.
Figure 2-21 Microsoft Store

Once the download is complete, open Ubuntu in the start menu. In the pop-up terminal, you can initialize, register user name, password, etc. If you have operated smoothly all the way, this installation is over.
If you get an error, I hope the solution provided by the author in the next section can help you.

2. Common mistakes in configuring WSL2 in Windows 11

1. Solve the problem that Hyper-V does not have

If there is no Hyper-V in the step of enabling the virtualization function in the control panel, you can solve it by the following methods.

1) First, create a new .txt file in the computer, and paste the following content into it.

1.pushd "%~dp0"    
2.dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt    
3.for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"    
4.del hyper-v.txt    
5.Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL    

2) Then save and change the file extension to ".cmd", then double-click to run it. If it is still a "txt" file after changing the name, it means that the name has only been changed, and the file format has not been changed successfully. The solution is shown in Figure 2-22.
Figure 2-22 Display file extension

After confirmation, change the suffix of the "txt" file name to "cmd" again, and double-click to run.

3) After the operation is complete, run the Microsoft-Hyper-V command just now in PowerShell under administrator privileges.

1.Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All      

2. Solve the bug about "???" when WSL starts Linux

The error result is shown in Figure 2-23.
Figure 2-23 "??????" bug
As a solution, download the official version of the software Windows Subsystem for Linux Update setup, and upgrade WSL1 to WSL2 to solve the problem.
After the download is complete, install the program with the default configuration, and the problem can be solved.

3. WSL subsystem initialization error

As shown in Figure 2-24, when the WSL system is started, an error "The attempted operation is not supported by the referenced object type" is reported.
Figure 2-24 The attempted operation is not supported by the referenced object type
The solution is to use the registry method. Copy the following code, create a new file "test.reg" (the file name can be chosen arbitrarily, and must end with .reg), and double-click to execute.

1.Windows Registry Editor Version 5.00    
2.[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\0408F7A3]    
3."AppFullPath"="C:\\Windows\\System32\\wsl.exe"    
4."PermittedLspCategories"=dword:80000000    

Three, VS Code remotely connects to WSL2

1. Download the plugin "Remote Development"

Using VS Code to remotely connect to WSL2 requires downloading a specific plug-in "Remote Development", as shown in Figure 2-25.
Figure 2-25 Installing the plug-in Remote Development

After the plug-in is installed, connect to the local WSL remotely as shown in Figure 2-26. The first time you enter the remote mode, it will be slower and you need to download some components, just wait patiently for the download.

2. Connect to WSL remotely

Figure 2-26 VS Code remotely connects to local WSL

Note, if you open this remote interface, if you do not find the WSL item, click the lower left corner, and then select the first item, as shown in Figure 2-27.
Figure 2-27 VS Code remotely connects to local WSL

Guess you like

Origin blog.csdn.net/qq_39297053/article/details/130661298