[PYTHON] Development environment construction (2020 version, WSL2 + VcXsrv)

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.

Introduced WSL2 (Windows Subsystem for Linux 2)

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.

Operation of Win function

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.

Linux distribution introduced

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.

Application of WSL2

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

Terminal application introduced

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.

Package installation

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.

X Server installation

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.

  1. Select multiple windows
  2. Select start no client
  3. Add -ac to Additional prameters for VcXsrv
  4. Save the configuration file in a neat place with Save configuration
  5. Press Finish to complete the setting

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.

How to move and sample

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

無題.png

If this graph is displayed, the environment has been built normally.

Other

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

Development environment construction (2020 version, WSL2 + VcXsrv)
Django development environment construction memo
[MEMO] [Development environment construction] Python
django project development environment construction
Linux environment construction (on WSL environment)
[MEMO] [Development environment construction] wine
Anaconda environment construction on Mac (2018 version)
[For beginners] Django -Development environment construction-
[Python3] Development environment construction << Windows edition >>
Emacs Python development environment construction memo
Ubuntu Desktop 20.04 development environment construction memo
Mac OS X Mavericks 10.9.5 Development environment construction
Python3 + venv + VSCode + macOS development environment construction
Mac OS X Yosemite 10.10 Development environment construction
Mac OS X development environment construction memo
Construction of development environment for Choreonoid class
Windows + gVim + Poetry python development environment construction
Django environment construction
DeepIE3D environment construction
Linux environment construction
Python environment construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Golang environment construction
python environment construction
Word2vec environment construction
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Kotlin / Native development environment construction & installation procedure & tutorial
Mac development environment construction (Ansible + Serverspec + Travis CI)
Mac OS X Mountain Lion 10.8.5 Development environment construction
From 0 to Django development environment construction to basic operation
Environment construction: GCP + Docker
Django project environment construction
python windows environment construction
Go language environment construction
ConoHa environment construction memo
homebrew python environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Google App Engine / Python development environment construction procedure (late 2014)
YOLO v4 environment construction ①
WSL2 environment construction example Python, Node.js, Java, git-secrets, Docker
pyenv + fish environment construction
Python development environment construction 2020 [From Python installation to poetry introduction]
BigGorilla environment construction memo
grip environment construction onCentOS6.5
Development environment in Python
Anaconda environment construction memo
Golang environment construction [goenv]
Mac environment construction Python
Pyxel environment construction (Mac)
[Memo] Django development environment
Python environment construction @ Win7
Building a Jupyter Lab development environment on WSL2 using Anaconda3
Construction of Python local development environment Part 2 (pyenv-virtualenv, pip usage)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
Construction of Cortex-M development environment for TOPPERS using Raspberry Pi
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction