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:
Install Windows Subsystem for Linux (WSL) on Windows 10
Windows Subsystem for Linux has two different versions to choose between during the installation process. WSL 2 has…
In Step 6, choose “Ubuntu 20.04 LTS”:
Install and Configure Windows Terminal
When Ubuntu is installed, install Windows Terminal:
Get Windows Terminal - Microsoft Store
The Windows Terminal is a modern, fast, efficient, powerful, and productive terminal application for users of…
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”:
You should see a JSON file which you can change to fit your taste. I have the following:
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:
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
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)
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.
A big THANK YOU to my colleague Marcus Windmark who helped me to get started with Python on Windows 🤗