Your Python Coding Environment on Windows: Setup Guide

Your Python Coding Environment on Windows: Setup Guide

by Ian Currie Reading time estimate 49m basics tools

Are you interested in writing Python code on a Windows machine? Maybe you’re a lifelong Windows user getting into coding with Python, or perhaps you’re just beginning to branch out from macOS or Linux. In this tutorial, you’ll walk through an easy-to-follow and flexible Python coding setup on Windows 10.

To set up your Windows machine for Python coding, you’ll:

  • Clean and update a new Windows install
  • Use a package manager to bulk install key software
  • Use the built-in ssh-keygen to generate SSH keys and connect to your GitHub account
  • Set up a development environment, including PowerShell Core, pyenv for Windows, Python, and VS Code
  • Examine scripts and tools to automate the setup and installation process

Along the way, you’ll learn about various recommended tools for a complete, free, and mostly open-source Windows Python coding setup. You won’t get to know all the possible tools, but you’ll walk away with one setup that should be flexible enough for most situations.

If you’re a beginner to intermediate Pythonista, or you’re just looking to get set up on a Windows machine without having to think about all the different options out there, then this tutorial is for you.

Maybe you’re in a rush to get set up. If that’s the case, then you’ll find what you need in the section on fast-tracking your setup, where you’ll examine a PowerShell script to automate the process almost entirely. Jump over there if you need to get up and running quickly. That said, going over the first section will give you a good checklist to start with to make sure you won’t run into any errors.

Take the Quiz: Test your knowledge with our interactive “Your Python Coding Environment on Windows: Setup Guide” quiz. You’ll receive a score upon completion to help you track your learning progress:


Interactive Quiz

Your Python Coding Environment on Windows: Setup Guide

Test your knowledge of setting up a Python dev environment on Windows, from updates and terminals to paths, tools, and WSL.

Setting Up Your Basic Python Coding Environment in Windows

Say you’re sitting in front of a completely fresh Windows installation. In this section, you’ll go through the first steps that you should perform in that case. You’ll get an initial command line environment set up, install software via package managers, and configure essential Windows settings for a Python coding setup.

In addition to installing what you need, you’ll also learn how to get around some of Microsoft’s built-in programs that might get in the way. Your first step is to ensure that your Windows installation is up-to-date.

Updating Your Windows Installation

First, if your machine is new or you’ve disabled updates, then you’ll want to make sure your Windows installation is up-to-date. Updating is especially relevant if you want to use Windows Subsystem for Linux (WSL) and have Windows 10. It’s also a safeguard against the dreaded Windows auto-reboot.

Installing Windows updates can take an hour or two, but it’s relatively mindless. So if you’re starting here, line up some other tasks while waiting for the updates to complete.

To start the update process, go to the Start menu and search for Windows Update. Once there, prompt Windows to search for, download, and install any updates it can find:

Windows updates control paned

Once all the updates have been installed, you’ll probably be prompted to reboot the computer. Do this as many times as it asks you to.

You’ll probably have to repeat the update process two or three times. Once the first batch of updates have been installed and you’ve rebooted, if you go back to the update screen, then it’ll probably say that the system is up-to-date. However, if you wait a while and then check for updates again, it’ll likely find some more to install.

Once you have all the updates installed, then you’re ready to do the initial setup for the command line environment in your Windows Python coding setup.

Discovering the Windows Terminal

If you’ve always used Windows, then you may be used to using the Command Prompt and PowerShell through their own apps. Opening them this way may make you think that they’re self-contained programs. However, when you run these programs from the Start menu, two processes are running. One process is what performs the commands, and the other is a process to send your input and display the output.

The window that you see when you open the Command Prompt is the displaying process. The core of the Command Prompt is in the background awaiting your input that’s sent by the window. In this way, the window acts as a sort of host to the terminal.

For more information about the differences between command interpreters and interfaces, take a look at the introduction to the shell section in the article about the subprocess module.

Windows has created a new, open-source Windows Terminal to be a universal console host. It acts as an interface to multiple shells, allowing you to start the Command Prompt, PowerShell, and any other shell that you might have available as different tabs in the same host:

Windows Terminal Sample

Until the new Windows Terminal, many relied on other hosts, also called emulators, to manage their different shell sessions as tabs or as horizontal and vertical splits. One popular choice was ConEmu. ConEmu has more features than the Windows Terminal. However, Windows Terminal is catching up and has some features that ConEmu doesn’t, such as Unicode emoji support.

Windows Terminal also has the advantage of having the development effort of the open-source community and Microsoft behind it. Windows Terminal is improving and adding features surprisingly quickly. Crucially, for this tutorial, Windows Terminal is a lot easier to set up than ConEmu, so if you’re following along, move on to the next section to install Windows Terminal.

Installing Windows Terminal

For this tutorial’s setup, you should install the Terminal app from the Microsoft Store, accessible from the Start menu. Installing it from the Microsoft Store has a few advantages. One advantage is that it ensures that updates come automatically. Another advantage is that it’s painless to install. Other sources seem to break relatively often, presumably because Windows Terminal is being developed very quickly.

Windows Terminal is the only app that you’ll install without the package manager that you’ll get to later in the tutorial. That said, hopefully soon you’ll be able to manage all your software under one package manager.

Once you’ve installed Windows Terminal with the Microsoft Store, you should be able to find it in the Start menu under Terminal. If, for whatever reason, you can’t install it from the Microsoft Store, try the releases page in the GitHub repository.

When you start Windows Terminal, it should automatically start up with a new PowerShell tab:

Windows Terminal with Windows PowerShell tab

With that working correctly, you’ll be switching gears to perform some general Windows adjustments.

Configuring General Windows Settings

There are some general Windows settings that you’ll want to set to keep your sanity in check. This section contains some typical settings that Windows users will often immediately change when setting up Windows. Most of these settings are optional. Just make sure you do the first one listed, coming up next.

App Execution Aliases

App execution aliases are a special kind of alias for Windows. For example, if you type python on the command line, Windows will automatically ask you if you want to install the Microsoft Store version of Python.

App execution aliases are a feature to make things easier to get started, but they can interfere with other programs. For instance, when you install pyenv for Windows and install a few Python versions, the app execution aliases will interfere by not allowing you to access those Python versions.

You can search for the app execution alias control panel from the Start menu. The entry is called Manage app execution aliases. Here’s a screenshot of that control panel:

Windows Control panel for app execution aliases

You can usually turn all of these off, as you already have the Path environment variable to make sure apps are available on the command line. More on environment variables are coming later in the tutorial. The essential ones to disable are the Python-related ones.

The rest of the settings in this subsection are optional but are recommended for quality of life.

Windows Updates

It’s worth keeping Windows up-to-date, not only for security but for updates to all the developer tools like Windows Terminal and WSL. One Windows quirk that you’ll want to avoid is the auto-restart. For that, you can disable the option to restart your device with the Advanced Windows update options control panel:

Windows Settings to turn off auto reboot

Here, you’ll want to disable the option to restart your device as soon as possible after installing a new update. This setting is what typically causes the dreaded Windows auto-restart.

Disabling the auto-restart function is still not watertight, though. You’ll want to reboot Windows every few days, or every week at least, to be safe. If there’s one thing that UNIX systems seem to be far better at, it’s being able to go without a reboot for ages.

Windows Explorer

In an attempt to make Windows Explorer easier to use for non-developer types, it hides some information that you’ll probably want to see, so you should enable the following:

  • Show file extensions
  • Show hidden files
  • Show protected operating system files
  • Show the full path in the title bar

You can access these options from the file explorer, which you can open with Win+E, click on the File tab in the top left, and choose Change folder and search options. Under the View tab, you’ll be able to find these settings:

Windows 10 File Explorer Settings

With those settings adjusted, you’ll be able to see the previously hidden files and file extensions.

Managing Software in Windows

The default option for most Windows users when installing software is to go to a website, download an executable, and run it. The executable is typically a Windows Installer Package with an .msi file extension. Then you’ll be presented with a User Account Control (UAC) screen, asking you for permission to make changes to your device:

Windows 10 User Account Control screen

If that wasn’t enough, you then have to read a license agreement, click OK a bunch of times, and then close the installer. There must be a better way!

On UNIX-based systems, you get nice things called package managers, like Homebrew, apt, dnf and pacman. Why can’t Windows have those? Well, Windows does have a few package managers to choose from, the most popular of which is Chocolatey.

Windows package managers aren’t quite as advanced as their UNIX-based equivalents. However, they’re a massive step in the right direction for people who like to get stuff done.

Microsoft is developing its package manager, winget. While it’s good and getting better fast, it’s still not the most popular package manager for Windows and doesn’t have nearly as many packages to choose from as Chocolatey.

Before installing Chocolatey, there are a few things that you’ll need to do first.

Loosening Your Execution Policy

To install Chocolatey, you’ll want to first open up Windows Terminal, or your terminal program of choice, as an administrator.

Once you have an administrator terminal session open, you should be presented with a PowerShell tab.

To be able to install Chocolatey effortlessly, and for the automation script later in the tutorial, you’ll need to set your execution policy to something less strict than the default.

The execution policy sets how strict your system is about running scripts from other sources. For this tutorial, you’ll want to set it to RemoteSigned:

Language: Windows PowerShell
PS> Set-ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you don't trust.
...
Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y

You may not see the warning, because the execution policy might already be set. To double-check your setting, you can run Get-ExecutionPolicy. Once you have the correct execution policy, then you’re ready to download and run a script that’ll install Chocolatey.

Installing Chocolatey

To run the Chocolatey install script and to run the automated setup script that you’ll be looking at later in the tutorial, you can make a request to a hosted version of the script.

To run the hosted version of the installation script, you can run this command:

Language: Windows PowerShell
PS> iwr -useb community.chocolatey.org/install.ps1 | iex

iwr is an alias for Invoke-WebRequest, and -useb means to use basic parsing, which downloads and parses the script from community.chocolatey.org/install.ps1. The result of this is the script text, which is then piped (|) into iex, which is an alias for Invoke-Expression, which runs the script. The script installs Chocolatey.

Once the installation is done, you should be able to call choco from the same prompt. However, the command is not always available from the same prompt after installation. In that case, you can restart the terminal, ensuring it’s still in administrator mode for what’s coming up in the tutorial. If that also fails, reboot your system to refresh the environment.

Using Chocolatey

With Chocolatey installed, you’re ready to manage almost all your software with simple commands. Remember that to install, upgrade, and uninstall software, you’ll need to start the Terminal session as an administrator.

Try starting an elevated Terminal session, and then install a package of your choice from the online package search. The install command is demonstrated below with 7zip, an open-source file archiver:

Language: Windows PowerShell
PS> choco install 7zip
7zip.install v22.0 [Approved]
7zip.install package files install completed. Performing other installation steps.
The package 7zip.install wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint):

At the confirmation prompt, type Y and press enter. Chocolatey will then install the package. If you want to disable the behavior of double-checking if you want to install a package, then you can send this command:

Language: Windows PowerShell
PS> choco feature enable -n allowGlobalConfirmation