Using WSL2 to set up a Spyder IDE on Windows 10

Sq_Mao
4 min readDec 15, 2020

In this article, we are going to set up a Spyder IDE with Windows Subsystem for Linux version 2 (WSL2) on Windows 10. If you want to know the difference between WSL 1 and WSL 2, click here. And if you want to use WLS 1 to build a Spyder IDE, click here.

Step1: keep your systems updated

Before we get started, we need to make sure our Windows 10 is updated.

Step 2: Enabling Virtual Machine Platform in Windows 10

We need a Virtual Machine Platform. Because we are using a subsystem, not a Dual-Boot System.

Run the following command in Windows PowerShell (“Run as Administrator”).

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

Note: This command will work if the operating system is Windows 10 Edition Version is ‘1903 or 1909’.

After you run the above command, you should see the following figure.

Note: If the “RestartNeeded” is “True”, you need to restart the operating system (Windows 10) before you move to the next step.

Step 3: Setting up Windows Subsystem for Linux version 2 (WSL2) on Windows 10

Download the Linux kernel update package and install it.

After the installation, run the following command in Windows PowerShell (Run as Administrator).

wsl --set-default-version 2

Step 4: Installing a Linux subsystem (Ubuntu 20.04)

Search Ubuntu in “Microsoft Store” and Install “Ubuntu 20.04”.

Note: The subsystem must be installed with your system drive.

Run “Ubuntu 20.04LTS” and create a username and a password.

Step 4: Installing the latest version of Miniconda

Run the following line to download the installer of the latest version of Miniconda.

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Install it by running the following command.

bash Miniconda3-latest-Linux-x86_64.sh

After the installation of Miniconda, we need to restart the Ubuntu terminal. And then you should see there is a “(base)” at the beginning of the line. That is, we are using “Miniconda Powershell”. All the “conda” command could work only in “Miniconda Powershell”.

Install Spyder IDE by the following command in “Miniconda Powershell”.

conda install spyder 

Furthermore, we need the following packages to make spyder work properly. Run the following lines in the Ubuntu terminal.

sudo apt-get install libxcursor-dev
sudo apt-get install alsa
sudo apt install libegl1-mesa libegl1

Step 5: Installing VcXsrv Windows X Server

Download “VcXsrv Windows X Server” to make Spyder IDE can be shown in Linux.

Install “VcXsrv Windows X Server” by default options and open it.

Input “0” in “Display number” and click “Next”.

Don’t change anything, and click “Next”.

Mark “Disable access control” and click “Next”.

Save the configuration and click “Finish”.

Note: You need to allow the VcXsrv windows server to communicate on both the private and public networks.

If not, you will see the following error in the Ubuntu terminal when you launch Spyder IDElater.

"QXcbConnection: Could not connect to display"

After you finished the installation of VcXsrv Windows X Server, run the following line in the Ubuntu terminal. (“nano” is an editor)

nano ~/.bashrc

Add the following two commands to the end of it. And save the file by pressing “CTRL + X”, “y” and “ENTER” sequentially.

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0export LIBGL_ALWAYS_INDIRECT=1

Final Step: Opening Spyder IDE

Input “spyder” in the Ubuntu terminal. The following figure means there are no errors.

Good job! Now we can do data analysis with Spyder IDE in a Linux subsystem.

Reference

  1. https://linuxh2o.com/how-to-install-wsl-2-on-windows-10/
  2. https://docs.microsoft.com/en-us/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package
  3. https://medium.com/@macasaetjohn/setting-up-a-spyder-environment-with-wsl-bb83716a44f3
  4. https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2

--

--