Previous article has passed since the environment has changed, so I updated it. The other day, WSL2 was released with a major update "Windows 10 May 2020 Update", so I will switch from Cygwin. Since it became easier to install packages such as numpy, I abandoned Anaconda and switched to pipenv management.
So the environment to build is
so
To be able to move. By the way, I'm using Windows 10 Pro 64bit, but there is no problem with Home.
May 2020 Update If Windows Update has not been updated, you can update from here. The update is fairly long, so wait with a cup of coffee.
From Control Panel → Programs and Features → Enable or Disable Windows Features
If you click OK, it will restart, so eat a donut and wait.
After rebooting, just in case, type a command from PowerShell.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
It is good if the message "Operation completed successfully" is displayed for each.
Install the distribution from the Microsoft Store. Ubuntu-20.04 is installed here, but 18.04 or Debian is also acceptable. In that case, read as appropriate.
After the installation is complete, start Ubuntu-20.04. It is quick to start from the screen installed in the Microsoft Store or from the start. When it starts up, a command prompt-like window will appear and the distribution will start initializing. This is also a little long, so I'll wait for it to wash in the kitchen.
After the initialization is completed, the password registration proceeds following the user name. The user here is admin, so don't forget it's the superuser's path.
Since WSL1 is applied to the installed Ubuntu, change it to WSL2.
First, open a command prompt to confirm that WSL1 is applied.
wsl -l -v
Hit. The distribution, status, and version you just installed are displayed. This version should be 1.
Update the Linux kernel for WSL2. Execute the file downloaded from the link below and install it.
https://docs.microsoft.com/ja-jp/windows/wsl/wsl2-kernel
After the installation is complete, return to the command prompt and type the following command.
wsl --set-version Ubuntu-20.04 2
once again
wsl -l -v
If the version is 2, it will be successful. Finally, hit the following command to set the standard distribution of wsl to this one.
wsl -s Ubuntu-20.04
Since the standard terminal is command prompt tick and very delicate, install the terminal application separately. Since Windows Terminal has been released by Microsoft, I will use it. It can be Fluent Terminal or wsltty.
After that, it will be operated on Ubuntu. First, update the installed package.
sudo apt update
sudo apt upgrade
Then install what you need.
sudo apt install vim
sudo apt install git
sudo apt install make
sudo apt install gcc
sudo apt install g++
sudo apt install gfortran
sudo apt install gdb
sudo apt install python3-tk
At this point, the environment for C / C ++ and Fortran 90/95 has been completed.
Next, pipenv is introduced as a Python environment. The explanation of pipenv is Official, here and [here] ](Https://qiita.com/y-tsutsu/items/54c10e0b2c6b565c887a).
pip install pipenv
Install with.
At this rate, graphical things such as matplotlib will not be displayed. You must install X Server for that. Here, install VcXsrv.
For the settings, refer to issue in the WSL repository.
VcXsrv's xlaunch.exe (Shortcuts should have been generated on the desktop if nothing was changed during installation) Start and configure X Server settings.
If you leave it as it is, you will have to start VcXsrv every time you restart your PC. So create the shortcut of config.xlaunch saved earlier in the Windows startup folder.
Also, add vcxsrv.exe outside the scope of the firewall. If you have security software installed, go to the security software settings. Other than that, set from the control panel.
The rest is in .bashrc as a setting on the WSL side
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
Is added.
Let's draw a graph as a test of the created environment.
mkdir sample
cd sample
pipenv install
pipenv shell
pipenv install numpy matplotlib
vim app.py
app.py
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, np.pi*2, 0.1)
y = np.sin(x)
plt.figure()
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('sin(x))
plt.grid()
plt.show()
python app.py
If this graph is displayed, the environment has been built normally.
From explorer
\\wsl$Ubuntu-20.04\home\user_name
You can access WSL files with. Very convenient.
You can edit files on the WSL side by introducing the remote extension in Visual Studio Code.
Recommended Posts