Python, pip, WSL 1 Debian Setup on Windows 10 1


This article will cover a condensed version of the setup of my Surface Laptop 3 running Windows 10. Starting from a clean format ready for Python development on Windows Subsystem for Linux WSL 1. I will refer to my other post on Surface Pro 3 as I followed similar steps with a few differences which I’ll discuss.

Let’s get cracking on a clean wipe, reinstall and setup of WSL 1 with Debian and Python using pip tools management.

Windows terminal preview with Vim and htop running in Linux panes along with multiple shells running in tabs
Windows Terminal Preview with Multiple Linux panes running Vim and htop. Multiple shell tabs shown for PowerShell and the Command Line

Reset My PC (Optional)

I like to reset my machine occasionally for some house cleaning. This is usually as simple as going to Start > Reset this PC > Get Started.

I wasn’t fortunate enough to go this route as my machine got all messed up, so I had to Recover from a USB.

I enabled the Windows Insider Programme to get WSL 2, but for some strange reason, Windows updates would kick out at the end with an error that this device wasn’t upgradable to the April 2020 version in July 2020!

If you find yourself in my predicament, then following these steps directly from Microsoft Surface Support.

Microsoft Support Email


Hello Bradley,
Thank you for contacting Microsoft Surface Support.
This is your service request # removed

Please follow these steps to carry out a USB recovery:
To download the image: https://support.microsoft.com/en-us/surfacerecoveryimage

  1. Continue without signing in
  2. Enter the model of your device “Surface”
  3. Enter the serial number.
  4. Download the image from the list.
  5. If the download doesn’t start and you see a red X next to the address bar, click on it and choose Always Allow. Click the download button again.

To prepare the USB: At least 16 GB or he most 32 GB

  1. Right click on the USB
  2. Click on Format
  3. On File System, choose Fat32
  4. Rename it as Surface Recovery
  5. Click start.

Once file is downloaded you need to extract the file to the USB, for this you may follow the next step:

  1. Right click over the downloaded file.
  2. Select “Extract all” or Extract to”
  3. A window will open showing a directory where you want to extract the file>>select browse to search for the USB
  4. Once USB found click Select folder, extraction will start
  5. Once extraction is done plug out USB

To prepare the Surface device:

  1. Turn off the device completely.
  2. To turn it on, press and hold the Volume Up button at the top of the device, and then press and release the power
    button without releasing the volume up. When you see the UEFI settings, release the Volume Up button.
  3. On the left panel, Boot configuration>drag and drop USB storage on the first place of the list.
  4. Press Exit on the left panel and restart.
    You will see a red band at the top with a white lock. This means your device is unlocked and ready to boot from an external device. Turn the device off, connect the USB and then press and hold Volume Down button and Power button. Follow the steps on the screen.

Best Regards,
J R
Surface Support
https://www.microsoft.com/surface/support


Formatting a USB Via DiskPart (If Required)

I only had one USB device handy, which was formatted with a Linux ISO image, and I wasn’t able to format it through File Explorer. I had to re-partition it for use in Windows recovery above.

Hopefully, you don’t have this issue, but if you do, here you go.

Step 1: Open up Microsoft DiskPart

Start > cmd > diskpart

Step 2: Select, Clean and Partition

Run the following commands:

Microsoft DiskPart version 10.0.19041.1

Copyright (C) Microsoft Corporation.
On computer: BGS-SP-3

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          238 GB      0 B        *
  Disk 1    Online           29 GB    29 GB

DISKPART> select Disk 1

Disk 1 is now the selected disk.

DISKPART> clean

DiskPart succeeded in cleaning the disk.

DISKPART> create partition primary

DiskPart succeeded in creating the specified partition.

DISKPART>

Step 3: Format

Windows Explorer > right click disk drive > Format

The USB is now ready as a recovery disk per the instructions above.

WSL Installs

WSL Distro

I followed the Install Windows Subsystem for Linux over here with some notes on deviations:

  • Stayed with WSL 1 for now. I will wait for WSL 2 in a future upgrade.
  • Tried Debian for this install.
  • Installed Windows terminal (preview) from the store as recommended in GitHub. The version in Chocolately was 1 minor release behind.

WSL Python

For this setup I did away with Conda and went the pip and venv route as outline here by Microsoft.

# We recommend updating your Linux distribution regularly
sudo apt update && sudo apt upgrade

# Install Python, pip, and venv
sudo apt-get install python3
python3 --version
>>> Python 3.7.3 

sudo apt install python3-pip

sudo apt install python3-venv

mkdir python-projects && cd python-projects
mkdir py37 && cd py37
python3 -m venv .venv
source .venv/bin/activate

# pyenv not available in Debian

python -m pip install pip-tools
cd ~
(.venv) bgs@SL3:~$

Installed the following common python packages with pip:

pip install ipykernel pandas numpy matplotlib scikit-learn

For future installs I will probably go with the Unix setup of: pyenv + pip + venv + pip-tools discussed in the article.

WSL Git

I installed and configured git locally and remotely on GitHub.

sudo apt install git

git --version
>>> git version 2.20.1

git config --global user.name "Bradley Sawler"
git config --global user.email "<email>"
git remote set-url origin git@github.com:<github-username>/<repo-name>

git config --list --show-origin

ssh-keygen -o
cat /home/bgs/.ssh/id_rsa.pub
>>> Copy and pasted into github.com

A great reference is the Pro Git book, written by Scott Chacon and Ben Straub.

WSL Extras

I installed the following through the bash terminal: vim, fasd, ripgrep, fd-find.

# wget required to run code . at shell
sudo apt-get install wget

# curl required to install from github
sudo apt-get install curl

# Install vim to clean up .bashrc and .vimrc copied over
sudo apt-install vim

# Install fasd
sudo apt-get install fasd

# ripgrep managed by Debian was older and didn't have the 
# -max-column-preview. Can install later once new version stable.
# check online for latest release and amend to suit.

curl -LO https://github.com/BurntSushi/ripgrep/releases/download/12.1.1/ripgrep_12.1.1_amd64.deb

# Install fd-find
sudo apt-get install fd-find

I copied my master version script files, which I control via git, over into the WSL root folder: .bashrc, .vimrc, .ripgreprc

Windows Installs

Package Manager and Python

Installed as outlined in the Windows Packager Manager over here.

Apps direct Download

Here are a list of a few programs I installed during the initial setup. Mainly captured here for reference only.

Visual Studio Code – I downloaded from the web instead of choco. I was looking into a fork of VS Code named VCCodium but it didn’t support (or I couldn’t find) a Remote – WSL Extension option.

Windows Terminal Preview – Installed from the Windows store. After installation I updated the settings.json accordingly:

// Update the default profile to the WSL guid
"defaultProfile": "{copy and paste from WSL defaults}",

// Add the WSL starting directory to suit. 
"startingDirectory": "//wsl$/Debian/home/bgs/python-projects/github/learning"

Obsidian – This is my current go-to application for writing my notes (and this article) in Markdown.

espanso is a cross-platform text expansion tool.

Apps from Chocolately

The following are some optional startup installs.

# Optional installs

choco install firefox
choco install qdir
choco install notepadplusplus
choco install typora
choco install PDFXchangeEditor

Post Setup

The following are just some updates performed after the initial setup. Might be worth considering.

Installed some packages on WSL:

# Manual pages db not installed on Debian by default.
sudo apt install man-db 
sudo apt install tree

Vim configuration edits:

# Open any possible bash profile files and direct them to .bashrc
# Discussed in Lynda course Unix Chpt 7

vim ~.bash_profile 


# go to bashrc in the event this file bash_profile is invoked
if [ -f ~.bashrc ]; then
    source ~/.bashrc
fi

End of the Road for Windows (for now)

My Surfaces have served me well, but I was finding the dual system cumbersome to work with. OneDrive is my primary storage facility and found jumping back and forth between Windows and Unix Python a pain.

I wanted a single based operating system where I would harness the power of the terminal and continue to use my online file hosting service (OneDrive through the 365 family account). So I returned to Apple. While I’ve never owned an iPhone or iPad, I had a MacBook in 2007 and a 2nd one in 2010 (both still working today).

I jumped online and ordered a MacBook and picked it up at the Apple store and took about 2 days setting it up to run as a developer machine. I will cover that setup in my third of 3 setup articles.

Happy Coding.


One thought on “Python, pip, WSL 1 Debian Setup on Windows 10

Comments are closed.