avatarMartin Thoma

Summary

The provided content is a comprehensive guide for beginners on setting up Python development on Windows 10 using the Windows Subsystem for Linux (WSL) with Ubuntu, and includes instructions on installing WSL2, Ubuntu, Windows Terminal, pyenv, and recommendations for Python tutorials and editors.

Abstract

The article "A Beginner’s Guide to Python Development on Windows 10" offers a detailed walkthrough for novice developers to set up a Python development environment on Windows 10 by leveraging the Windows Subsystem for Linux (WSL). It emphasizes the benefits of using Linux, particularly Ubuntu, through WSL2 to overcome the suboptimal Python support on native Windows. The guide covers the installation of WSL2, Ubuntu, and the Windows Terminal, as well as the configuration of the terminal with Powerline fonts for a more aesthetically pleasing interface. It also explains how to install pyenv for Python version management and recommends installing Python version 3.8.6. The article concludes with editor suggestions, such as Visual Studio Code, Sublime Text, and PyCharm Professional, and advises on navigating between Windows and Linux file systems. For learning resources, it points to the official Python tutorial and a jumpstart course by building 10 apps, acknowledging the help received from a colleague in the process.

Opinions

  • The author suggests that using Linux through WSL2 is preferable for Python development on Windows due to the prevalent use of Linux among Python developers and the platform-specific code in some Python packages.
  • The article implies a lack of comprehensive Python support on Windows by highlighting the ease of following Linux-based tutorials when using WSL2.
  • The recommendation of pyenv indicates the author's preference for flexibility in managing multiple Python versions.
  • The author expresses a personal preference for Sublime Text as an editor due to its lightweight and distraction-free environment, while also acknowledging other popular editors like Visual Studio Code and PyCharm Professional.
  • The mention of the official Python tutorial and the Python Jumpstart course suggests that the author values structured learning for beginners, regardless of prior programming experience.
  • The author expresses gratitude towards a colleague, Marcus Windmark, for assisting with Python setup on Windows, indicating a collaborative approach to learning and development.

A Beginner’s Guide to Python Development on Windows 10

Using Linux 😄

Image by Martin Thoma

The Python programming language is used for web development, data analysis, machine learning, statistics, web scraping, and so much more. There are tons of tutorials which, ironically, makes it pretty hard to recommend one. However, there is also a lack of support for Windows.

Let’s get the very first step done: Install it on Windows. You could use Python through Anaconda, but in this article, we will use it on Windows with WSL. This prepares you to go with one of the many tutorials to start your Python career.

What is WSL?

The Windows Subsystem for Linux (WSL) is a compatibility layer that allows you to run Linux binaries on Windows. WSL2 uses the Linux Kernel (source). On top of WSL, you can run the Linux-flavor “Ubuntu”. Such a kind of “flavor” is called a distribution. There are many other distributions, but Ubuntu is by far the most wide-spread option.

This is pretty awesome because most Python developers use Linux. This means many tutorials assume that you have access to Linux programs and some Python packages contain code that is platform-specific. The Python community is increasingly becoming aware of the issue that Windows support is sub-optimal, but for now, using (something similar to) Linux is just the easier path.

Install WSL2 and Ubuntu

I recommend to follow the official Microsoft guide:

In Step 6, choose “Ubuntu 20.04 LTS”:

Install and Configure Windows Terminal

When Ubuntu is installed, install Windows Terminal:

Download and install all 4 “DejaVu Sans Mono Powerline” fonts.

Launch a terminal and navigate to the settings. It’s this small downwards pointing “arrow”:

Click on “Settings”. The screenshot was taken by Martin Thoma

You should see a JSON file which you can change to fit your taste. I have the following:

Install pyenv

pyenv lets you run any Python runtime you like. To install it, run the following commands. Lines that begin with $ indicate that you should enter what follows. Copy everything except the $ until the next $

$ sudo apt-get install git
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
# Copy the next two lines, except the first $
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
# Copy the next two lines, except the first $
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc
# Install the build dependencies
$ sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Close all terminals and open one again. Now the command pyenv should show you the help:

Screenshot by Martin Thoma

Most importantly the command pyenv install --list which shows you all the different Python versions you can install. I recommend installing 3.8.6 as of October 2020.

$ pyenv install 3.8.6
Downloading Python-3.8.6.tar.xz...
-> https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tar.xz
Installing Python-3.8.6...
Installed Python-3.8.6 to /home/math/.pyenv/versions/3.8.6

After that, you can use it globally:

$ pyenv global 3.8.6
$ python --version
Python 3.8.6
$ pip --version
pip 20.2.1 from /home/math/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pip (python 3.8)

Editor

There are two beginner-friendly, gratis, wide-spread editor options: Visual Studio Code and Sublime Text. A lot of people also like PyCharm Professional and some hackers like vim / Emacs. Personally, I do most of my work in Sublime Text. I like that it is super lightweight and doesn’t have a lot of distracting information.

I highly recommend navigating within Windows to \\wsl$\Ubuntu\home . So you are within Windows on the Linux part.

You can also go to /mnt/c/Users within Ubuntu, but this way things become crazy slow.

How can I continue?

If you want an introduction to Python from the beginning, try the official Python tutorial. Although I already had programming experience when I started with Python, I went through this to make sure I know the basics.

If you have some programming background, there is also the Python Jumpstart by building 10 apps. I haven’t tried it, but I love the talk Python podcast.

Acknowledgment

A big THANK YOU to my colleague Marcus Windmark who helped me to get started with Python on Windows 🤗

Programming
Python
Beginners Guide
Windows 10
Software Development
Recommended from ReadMedium
avatarAbhay Kumar
OOPs in Python

An easy guide

10 min read