Python on Windows

State of the Art

@nicolaiarocci

Question

How many of you in this room are on Windows?

The Goals of this talk

Quite ambitious ones

1. Awareness of Windows relevance for Python

2. Make your code "just work" on Windows

3. Wonders of Python development on Windows

Python userbase

Our perception

Make sure your libs "just work" on Windows

  • Make sure -m works on your project
  • Use pathlib.path to handle paths
  • Adopt appdirs to store user and configuration data
  • Use str to let Python handle encoding at OS boundaries. Do your own IO stream conversions.
  • Get CI, collaborate, or...

more info at https://youtu.be/uoI57uMdDD4

Python development on Windows

  • Python tooling has been rapidly evolving
  • One-click install from the Microsoft Store
  • Visual Studio has great Python support
  • VSCode+Python extension works on Windows too
  • A brand new Windows Terminal
  • Windows Subsystem for Linux 2

One-click install from the Store

Visual Studio

  • Python install from VS Installer
  • Package Management
  • Virtual Environments
  • IntelliSense and code analysis
  • Interactive debugging (remote too)
  • Unit Tests
  • Templates (Django, Flask, PyGame, etc.)
  • Code Imports
  • Jupyter support
  • REPL
  • Community edition is free

PyCharm also works great on Windows.

Windows Terminal (Preview)

Windows Terminal (Preview)

  • Multiple Tabs
  • Command Prompt, PowerShell, Linux
  • GPU accelerated text rendering
  • glyps, emojis, ideograms, symbols, icons, ligatures
  • Fully configurable and custimizable via json
  • Multiple profiles
  • Cascadia Code font, with ligatures (Preview)
  • Open Source (link)

cool video at https://aka.ms/terminal-video

Windows Subsystem for Linux 2

WSL2 Quick Facts

Runs ELF64 Linux binaries on Windows

WSL2 Quick Facts

Windows ships with a Linux kernel

WSL2 Quick Facts

  • WSL2 runs on a lightweight utility virtual machine
  • Super fast boot, small footprint, zero configuration
  • Both WSL2 and Linux kernel are Open Source (link)

One-click install of Linux distributions

DEMO #1

LINUX ON WINDOWS, WITH TERMINAL

WSL2 IS IN PREVIEW

JOIN THE INSIDER PROGRAM (Fast ring)

You also need to know

Spare yourself some pain

  • BIOS virtualization must be active
  • Virtual Machine Platform feature must be active
  • WSL feature must be active
  • distros will be on WSL1 once installed
  • status: wsl --list --verbose *
  • switch to v2: wsl --set-version Ubuntu 2 *
  • set v2 as default: wsl --set-default-version 2 *

(*) in PowerShell, as admin

However...

One small problem

  • WSL has no GUI
  • You can't install a visual tool like VSCode
  • We do have interop between Windows and Linux
  • Microsoft recommends that you do not alter files in the WSL side with Windows programs...

Remote extension

to the rescue

Code + Remote + WSL2

Windows-side Code, connected to Linux

Code + Remote + WSL2

Courtesy of Remote extension

Code + Remote + WSL2

Extensions work across boundaries

DEMO #2

Code + Remote + WSL

BTW Remote extension

Connects to

Python in the WSL

Key points

  • Run Windows and Linux side-by-side
  • Multiple linux distros, one-click away
  • No heavyweight VMs
  • Leverage your existing bash/linux skills
  • Powerful desktop applications
  • Rich eco-system (omg games!)
  • Innovation happens right here

QUESTIONS?

  • WSL2 uses Hyper-V
    • VirtualBox 6+ -OK!
    • Hypervisor Platform API for third-party virtualization providers
  • WSL2 can run in a VM
    • Needs nested virtualization enabled
  • Networking apps?
    • Yes! Will have different IP than host *
  • GPU is currently a no go *

* high on the backlog

Suggested reading

Smashing Magazine (link)

Thank You!

@nicolaiarocci







special thanks
@zooba