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.
Note: Most of the steps here will work equally well on Windows 11.
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-keygento 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.
Free Bonus: Click here to get our free Python Cheat Sheet that shows you the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.
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.
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.
Note: If youβre going to be following along, youβll be restarting your computer various times during this whole process. Itβs worthwhile to have another device close by, not only for keeping this tutorial open, but for general queries, troubleshooting, and the ability to carry on reading other Real Python tutorials while waiting for updates or installations.
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:

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:

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.
Note: You arenβt required to use Windows Terminal for this tutorial, but itβs recommended. It seems like in the UNIX world, itβs much more common for people to use the command line, and this is partly because of the nice features of the terminal emulators available.
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:

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:

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:

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:

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:

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.
Note: To launch programs as an administrator, you can search for the app in the Start menu, and then right-click on it, and choose Run as administrator.
To run a program as an administrator is also referred to as running an elevated instance of the program. It can also be called running a program with elevated privileges.
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:
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.
Note: Youβll always be told to check the sources for remote scripts before running them, as malicious actors can exploit this technique.
For example, if someone were to hack the community.chocolatey.org/install.ps1 URL and replace it with a malicious script, this could wreak havoc on your machine. So, be careful to check that the source hasnβt been compromised.
To run the hosted version of the installation script, you can run this command:
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.
Note: Having to start the whole program as an administrator can be a bit of a hassle. Usually, you only want to run a handful of commands as an administrator, so having to start the whole program in administrator mode often feels a bit overkill.
In UNIX environments, thereβs a handy sudo command that you can prefix to any command to run that particular command with elevated privileges. This command would be ideal for installing packages, if only it were available on Windows.
Fortunately, you can install a package called gsudo, which allows almost this exact functionality. Youβll still have to click on the UAC screen, but you wonβt need to open a whole new program instance to install something.
However, installing gsudo isnβt necessary to follow this tutorial.
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:
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:
PS> choco feature enable -n allowGlobalConfirmation
Now the installation process wonβt prompt you with the annoying Are you sure? type of prompts. That said, you can also pass in this option for each install command by adding the -y flag.
If you want to search available packages from the command line, then you can do that with the choco search [keyword] command. To see a list of your installed packages, you can use the choco list command with the --local-only flag. Finally, to upgrade and uninstall, there are choco upgrade and choco uninstall commands for that too:
PS> choco upgrade [package-name]
PS> choco upgrade all # keyword to try upgrade all packages
PS> choco uninstall [package-name]
Note that upgrading all packages might take a while.
Youβre now ready to start using Chocolatey by installing a small set of software to help you clean up and uninstall any bloatware that may have come preinstalled on your system.
Debloating Your Machine and Uninstallating Software
Once you have your package manager, one of the first things you may want to do with a fresh install is to clean it up. This section is optional and may not even be necessary for your system.
If youβve installed Windows from a Microsoft image, then thereβs probably not much to remove. If your PC came preinstalled, then itβs potentially filled with a bunch of bloatware.
For instance, manufacturers often include third-party antivirus software but may not deactivate Windows Defender. Having more than one antivirus software can cause strange problems and significantly impact your PCβs performance. Besides, Windows Defender or Microsoft Defender is safe, so if you donβt need the additional antivirus for any particular reason, you can rest assured that the built-in antivirus is adequate to keep you safe.
To start off with an immaculate install on a preinstalled system, some would even go as far as to reset the Windows installation completely. This option is available via the Start menu by searching for reset. However, this nuclear option can turn out to be a hassle because your machine may require special drivers that the Windows install process doesnβt have access to.
Itβs also inevitable that at some point, youβll install something that didnβt turn out to be what you wanted. Perhaps it was a package that wasnβt available on Chocolatey, or you just forgot to use Chocolatey. Or, to your horror, you clicked a suspect link and installed some persistent spyware.
To clean up and remove programs, you might want a decent uninstaller, ideally one thatβll let you uninstall in bulk and will also do the extra work of cleaning up files and folders that sometimes get left behind.
Spyware, malware, and adware that slip through the cracks are especially good at leaving behind services that reinstall themselves once youβve supposedly uninstalled them.
Bulk Crap Uninstaller or BCU, is a fantastic open-source uninstaller thatβll seek out all sorts of programs and purge them:
PS> choco install bulk-crap-uninstaller
Once itβs installed and open, itβll allow you to select multiple programs and automate the uninstallation and cleanup process as much as possible:

BCU will detect which uninstallation processes canβt be automated and uninstall those first. Then itβll let you know that all the rest of the programs can be uninstalled without your intervention.
After the main uninstall process, BCU will perform a deep clean, showing you leftover files, services, and registry entries that you may want to delete.
Note: Be careful when removing registry entries, as this can affect other programs!
Other free options are available, such as Geek Uninstaller, which is generally faster if all youβre looking to do is uninstall one or two programs.
Note: If you see some programs that are already installed on your system but have Chocolatey packages available, it might be worth uninstalling them and reinstalling them with Chocolatey. Once programs are all under the same package manager, updating and uninstalling them is far more manageable.
Some programs are very difficult to uninstall because theyβre deeply embedded into Windows. If you want to minimize their presence, then you may also want to play around with Winaero Tweaker:
PS> choco install winaero-tweaker
Winaero Tweaker is a utility thatβll allow you to change a bunch of settings that are either not accessible with the Settings app or are very difficult to change. For example, it can disable Cortana and OneDrive if you donβt intend to use them.
Note: After youβve installed your browser and other software, you may want to open the Default apps control panel, also searchable from the Start menu, and set your preferred applications as default.
One change thatβs common to make is changing the default browser from Edge. Windows will make one last-ditch attempt to convince you to use Edge, but press boldly ahead if you prefer another browser!
Once youβre done with general cleaning, itβs time to dig in further and explore the Windows command line experience.
Configuring Environment Variables
Environment variables are general-purpose key-value pairs that are available at many levels of the operating system. They typically contain information about how to run programs, or where to find resources. Python, for instance, runs differently if certain environment variables are set or not.
While you shouldnβt need to do much in terms of your own configuration as part of getting your machine set up, itβs always something that comes up sooner or later when troubleshooting. So itβs worth knowing your way around this topic.
Discovering Environment Variables With PowerShell
PowerShell has access to environment variables and a lot of related functionality. If youβre interested in digging deeper, Microsoft has a page dedicated to these variables in the PowerShell documentation.
To see all the environment variables available to your current PowerShell session, you can navigate to a pseudo drive called ENV, just as if it were a drive like C or D:
PS> cd ENV:
PS> pwd # alias for Get-Location
Path
----
Env:\
PS> ls
Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
ANSICON 166x32766 (166x66)
ANSICON_DEF 7
APPDATA C:\Users\RealPython\AppData\Roaming
AZ_ENABLED False
ChocolateyInstall C:\ProgramData\chocolatey
...
Once youβve navigated to the ENV: pseudo drive, you can call ls to list all the environment variables available to your current PowerShell session.
Note: PowerShell, like Windows in general, is case insensitive. So a path or a variable like $PROFILE can be accessed with $profile too. ENV can be accessed with env. This also holds true for filenames and paths.
Thereβs also a Graphical User Interface (GUI) control panel for environment variables, which youβll come to later in this section.
Environment variables are different from variables like $PROFILE because the environment variables are typically available to all programs in your user space, while $PROFILE is a PowerShell-only variable.
The Env:Path variable is particularly prone to easy mistakes and can be frustrating if you donβt understand whatβs happening.
Understanding the Path Environment Variable
One of the environment variables you should become familiar with is the Path environment variable. Path is a variable that contains a list of paths to directories that contain executables. Path is kept by your system as a way to have programs always close at hand.
You can see the Path environment variable in action whenever you call choco or python from the command line, for instance. You know that the target executable may not be in the current working directory, but Windows can still start it.
For instance, Chocolatey adds a directory to Path where it puts executables that you might want to call from the command line. The directory it adds to the Path environment variable is C:\ProgramData\chocolatey\bin, and in that directory youβll at least find choco.exe. With this set, when you call choco from the command line, Windows will search each path in the Path environment variable for a folder that contains a choco executable.
To see what paths are in your Path variable, from PowerShell you can call the following command:
PS> (cat ENV:Path) -Split ";"
cat is an alias for Get-Content, which returns a string object of the contents of the Path variable. You can wrap that object in brackets to call the -Split operator to see each path on a separate line.
The list visible after running the previous command is the list of locations that your system will look for when evaluating which program to run. Once you have Python installed, the location of the Python executable will need to be added so that you can
call python from anywhere.
Note: Watch out for having multiple possible choices for any given executable in Path. If, for example, you had a python.exe in two different places in Path, the one to run will always be the first one.
With some knowledge of environment variables and the Path variable, youβre now ready to learn how to make changes to them if necessary.
Setting and Changing Environment Variables
There are various ways to change environment variablesβthe most common being with the GUI control panel.
Open the Start menu and search for Edit the system environment variables, which opens up a System Properties window. In the Advanced tab, click on the button Environment Variables. There youβll see User and System variables, which youβll be able to edit:
If youβre the only user of your computer, then you can just set the user variables. If you want the variable to be accessible by all users on the machine, set the system variables.
You can also set environment variables from an elevated PowerShell prompt by using .NET API methods, like this:
PS> [Environment]::SetEnvironmentVariable("TEST", "VALUE", "User")
This command sets an environment variable with the key "TEST", whose value is "VALUE", and whose scope is "User". The scope can be "User", "Process" or "Machine". You can use "Machine" if you want the environment variable to be available to all users, while "User" is for just the current user. The "Process" scope will only set a variable for the current PowerShell session and the sessionβs child processes.
You can create temporary environment variables with pure PowerShell by using the following command:
PS> $ENV:TEST = "VALUE"
But a program outside the context of your PowerShell session wonβt have access to that variable. Whatβs more, if you donβt add this statement to your profile too, then it wonβt be available in your next PowerShell session.
If you need to change the Path variable, there are a few more things to bear in mind.
Changing the Path Environment Variable
Because the Path environment variable is a list of many paths, you need to be careful when modifying it, so that you donβt overwrite the whole Path with just one path.
Typically, if youβre going to be doing that from PowerShell as a temporary environment variable, then youβll need to append the new value with string concatenation:
PS> $env:Path = "$env:Path;C:\new\path"
Perhaps the easiest way to change the Path environment variable is with the GUI control panel, which keeps each Path entry on its own line, so itβs easier to avoid making a mistake.
Youβll often need to restart the shell session for any changes to environment variables to take effect. Chocolatey comes with a utility script that allows you to refresh the environment:
PS> refreshenv
Note that this wonβt work if you installed Chocolatey in the same session. That said, sometimes even with that script, itβs going to be necessary to reboot.
Now that you know how to do some Path troubleshooting and are relatively comfortable with your new command-line setup, itβs time to install Python with pyenv for Windows.
Setting Up Core Python Coding Software in Windows
Now itβs time to get set up with a few different Python versions. Even though itβs a good idea to keep up-to-date with the latest version of Python, itβs not uncommon to run into projects that wonβt work with the latest and greatest. There are even programs that still run Python 2, after all! So itβs best to be ready to install any number of versions of Python, and to be able to switch between them easily.
Installing Python With pyenv for Windows
pyenv for Windows is a port of the original pyenv which only runs on UNIX-based systems. The Windows version isnβt quite as fully featured as the UNIX version, but itβs still fully functional.
With Chocolatey, installing pyenv for Windows is just like installing any other package:
PS> choco install pyenv-win
Once pyenv for Windows is installed, youβll want to update the local index of Python versions available for install, which takes a few minutes. After the update is done, youβll want to install a couple of versions of Python:
PS> pyenv update
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Info] :: Scanned 172 pages and found 563 installers.
PS> pyenv install --quiet 3.10.5 3.9.12
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Downloading] :: 3.10.5 ...
...
:: [Installing] :: 3.10.5 ...
:: [Downloading] :: 3.9.12 ...
...
:: [Installing] :: 3.9.12 ...
The install command will install two Python versions without your manual intervention because of the --quiet flag.
You can use the pyenv global command to switch between Python versions and then check the version of Python thatβs active with the -V for version flag:
PS> pyenv global 3.10.5
PS> python -V
Python 3.10.5
PS> pyenv global 3.9.12
PS> python -V
Python 3.9.12
As you can see, switching between different Python versions is only a matter of one command.
Note: Remember that youβll need to have your Python-related app execution aliases disabled for pyenv for Windows to work correctly. They must be disabled because both the app execution aliases and pyenv for Windows intercept the python command. App execution aliases seem to take precedence and so will block the python command before pyenv for Windows gets a chance.
If you have a project requiring a specific version of Python, you have a few options for handling that. You can use the pyenv local command, which will create a file in the current working directory to ensure youβre always running that version of Python while in that directory.
Or you can create a virtual environment with that version active:
PS> pyenv global 3.9.12
PS> python -V
Python 3.9.12
PS> python -m venv venv
PS> pyenv global 3.10.5
PS> python -V
Python 3.10.5
PS> venv/Scripts/activate
(venv) PS> python -V
Python 3.9.12
If you create a Python virtual environment with a particular version of Python active, then that virtual environment will keep pointing to that version of Python.
For more in-depth information about pyenv, check out the dedicated tutorial on it. Just note that since that tutorial is for the UNIX version, some functionality may not work as it does on Windows. In those cases, check out the pyenv for Windows repository.
Now that you have Python, youβll want a way to collaborate with other programmers.
Installing Git on Windows
Git is the most popular and widely supported version control system among programmers. If youβve never used a version control system before, it manages changes to your project, allowing you to roll back to any state your code has been in from the moment you started using version control.
Git works with repositories. A repository is basically a folder with a tracked history. GitHub is a website that allows you to host your repositories. Once a repository is hosted, many people can work on the project simultaneously and from anywhere. You can work offline and then sync back up to the main repository once you connect to the Internet.
Git is easy to install with Chocolatey:
PS> choco install git
Thatβs it! You should now be able to call git from the PowerShell prompt. If this doesnβt work and you get a message saying that this command canβt be recognized, try refreshenv. If that fails, then you can resort to restarting the PowerShell session or just rebooting the machine.
Git, like PowerShell, also searches for a config file in the userβs home folder. You can create this manually in the root home path, or by using some built-in Git commands:
PS> git config --global user.name "John Doe"
PS> git config --global user.email john.doe@domain.com
That said, if you try to make a commit, Git will prompt you to add this information, which will create the .gitconfig file.
With Git up and running, youβll want to be able to connect with GitHub from the command line, but for that, youβll need to set up your SSH key.
Using SSH to Connect to GitHub
The way to connect to GitHub is with SSH, or Secure Shell. For this, youβll need to create some SSH keys. The process that youβll follow in this section will generate two keys, a private and a public one. Youβll be uploading the public one to your GitHub account.
Open up a PowerShell session and make sure that you have Open-SSH, which shouldβve been installed by default:
PS> ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user@]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
If you donβt see a similar output, follow the instructions on the Windows documentation to install Open-SSH. You can also install it from a Chocolatey package.
Youβll first create your keys with ssh-keygen, pressing enter at each prompt to use the default option:
PS> ssh-keygen -C john.doe@domain.com
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Real Python/.ssh.id_rsa):
Created directory 'c:\Users|Real Python/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Real Python/.ssh/id_rsa.
Your public key has been saved in C:\Users\Real Python/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa jondoe@domain.com
The key's randomart image is:
+---[RSA 3072]----+
| E+===+*++.o. |
|..=+=o+O+ o.o |
|o+o++.B.o oo |
|o+o*oo o o . |
| o+o. S . |
| o |
| |
| |
| |
+----[SHA256]-----+
You can add a passphrase if you want extra protection, but itβs convenient not to have to input your password every time you push your work to GitHub. With your keys generated, output the contents of the public key so that you can select and copy it to your clipboard:
PS> cat ~/.ssh/id_rsa.pub
The output of this last cat command is what youβll need to copy into your GitHub account.
To copy the key to your GitHub account, you first must make sure that youβve signed up for an account. Once youβve signed up and logged in, if you go to your GitHub settings, you should find the option to manage your SSH and GPG keys. Once in there, you should be able to see where to paste your SSH key.
After that, you can test the connection:
PS> ssh -T git@github.com
Hi John Doe! You've successfully authenticated, but GitHub doesn't provide shell access.
If you get this successful authentication message, then youβre ready to work with GitHub from the command line.
Now that you have Git up and running, itβs time to set up your code editor.
Setting Up VS Code
VS Code is an amazingly extensible free, mostly open-source, general-purpose editor. Itβs also the most popular. It can be used for many languages, but in this section, youβll get it set up for Python.
You can install VS Code with Chocolatey:
PS> choco install vscode
Remember to run the install command from an elevated PowerShell prompt.
VS Code has a rich extension ecosystem to aid your productivity. The official Microsoft Python extension often comes installed by default, but if not, you should make sure to install it.
To install an extension, you click the extensions icon in the activity bar:

Then use the search box to search for the Python extension linked above.
The Python extension will provide you with IntelliSense for Python, which is a way for your editor to give you suggestions for autocomplete and will provide you a wealth of information in detailed tooltips.
Another extension, if you plan on using WSL, is the WSL connector, which will allow you to edit files as if you were running on Linux.
Itβs also worth setting up Settings Sync, since thatβll link your VS Code settings and your extension list to your GitHub or Microsoft account, taking care of backup and making it fast to get set up on a new machine.
With VS Code set up, youβre ready to test your setup to ensure that itβs working.
Testing Out Your Setup
Congratulations, youβre pretty much good to go. In this section, youβll quickly test your setup to ensure everything is working correctly.
In the following snippet, youβll test out creating a folder, creating a virtual environment, installing a package, initializing a Git repository, and making sure that VS Code integrates with that setup:
PS> mkdir test
Directory: C:\Users\RealPython
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 27/06/22 18:19 test
PS> cd test
PS> pyenv versions
* 3.10.5 (set by C:\Users\RealPython\.pyenv\pyenv-win\version)
3.9.12
PS> python -m venv venv
PS> venv\Scripts\activate
(venv) PS> python -m pip install requests
Collecting requests
...
Successfully installed certifi charset-normalizer idna requests urllib3
(venv) PS> git init
Initialized empty Git repository in C:/Users/RealPython/test/.git/
(venv) PS> ni test.py
Directory: C:\Users\RealPython\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 27/06/22 18:25 0 test.py
(venv) PS> code .
With VS Code now open, at the bottom right, you should be able to see which Python environment youβre in:
If itβs not showing venv and IntelliSense isnβt working, then you can invoke the command palette with Ctrl+Shift+P and search for the Python: Select Interpreter command. Choose the option that points to the path of your virtual environment. With the virtual environment selected, VS Code should display at the bottom of your VS Code Window as 3.10.5 (βvenvβ:venv).
You should also be able to see VS Codeβs Git integration working. If you change a file or add a new one, then youβll see indications of that change in the editor window and the file explorer.
Well done! You now have a powerful and flexible setup on Windows. While using a package manager is far more efficient than manually downloading and executing installers, maybe youβre looking for an even faster way.
Fast-Tracking Your Windows Python Coding Setup
Maybe this is all a bit slow for you, or perhaps you just want to get started with automating the process. There are tools to automate installation at an industrial scale, like Boxstarter and Ansible, but this section is aimed more toward tinkerers who want to see what kind of things you can do yourself.
In this section, youβll fast-track your minimal setup, skipping any extra steps, and get developing as soon as humanly possible.
Configuration Repository
When first trying to automate a new installation, you typically run into the issue of getting your scripts onto the new machine to run them. A file syncing service can work, but those often take a long time to do their initial sync.
A great solution to this problem is having a repository containing configuration files and scripts. Sometimes other snippets may be included there, tooβsort of a coderβs personal cookbook.
Here, you can keep your PowerShell profile, your Git config files, other config files, and any scripts or notes that you might want. Once you have files hosted on GitHub, then you can get raw links to them and use PowerShell to download them:

To get a raw link, navigate to the file that you want to use in GitHub, and when youβre looking at the contents of the file, you should be able to see a button that says Raw. This button will take you to a URL that looks something like this:
https://raw.githubusercontent.com/[USER]/[REPO]/[COMMIT_SHA_OR_BRANCH]/path/to/file
Now you can use this URL to fetch the content and run it from your new machine. You can also host individual files with a GitHub Gist.
To take things a step further, to avoid having to type out the whole link, you can pass it through a URL shortener such as bitly, which will shorten the link:
https://bit.ly/xxxxxxx
Now itβs time to do the main bulk of setup. Armed with this short link, all you have to do is disable the Python-related app execution aliases, start an elevated PowerShell session, and run the following:
PS> Set-ExecutionPolicy RemoteSigned -Force
PS> iwr -useb bit.ly/xxxxxxx | iex
Then everything will be taken care of for you, and you can run an errand while the installation process ticks along. Now that youβve chosen your platform for hosting your setup script, youβll need the actual script!
Running a Setup Script
In this section, youβll examine a sample installation script thatβll install some minimal dependencies that youβll probably need to code with Python, especially if you want to contribute to open-source projects on GitHub.
The prerequisites for running this script are:
- Setting your execution policy to
RemoteSigned - Disabling Python-related app execution aliases
With those two tasks done, youβre just about ready to expand the collapsible box below and run the script:
# setup.ps1
Write-Output "Downloading and installing Chocolatey"
Invoke-WebRequest -useb community.chocolatey.org/install.ps1 | Invoke-Expression
Write-Output "Configuring Chocolatey"
choco feature enable -n allowGlobalConfirmation
Write-Output "Installing Chocolatey Packages"
choco install powershell-core
choco install vscode
choco install git --package-parameters="/NoAutoCrlf /NoShellIntegration"
choco install pyenv-win
# The Google Chrome package often gets out of sync because it updates so
# frequently. Ignoring checksums is a way to force install it.
choco install googlechrome --ignore-checksums
# Google Chrome auto-updates so you can pin it to prevent Chocolatey from
# trying to upgrade it and inadvertently downgrading it.
# You could also add VS Code here if you like.
choco pin add -n googlechrome
refreshenv
# The refreshenv command usually doesn't work on first install.
# This is a way to make sure that the Path gets updated for the following
# operations that require Path to be refreshed.
# Source: https://stackoverflow.com/a/22670892/10445017
foreach ($level in "Machine", "User") {
[Environment]::GetEnvironmentVariables($level).GetEnumerator() |
ForEach-Object {
if ($_.Name -match 'Path$') {
$combined_path = (Get-Content "Env:$($_.Name)") + ";$($_.Value)"
$_.Value = (
($combined_path -split ';' | Select-Object -unique) -join ';'
)
}
$_
} | Set-Content -Path { "Env:$($_.Name)" }
}
Write-Output "Setting up pyenv and installing Python"
pyenv update
pyenv install --quiet 3.10.5 3.9.12
pyenv global 3.10.5
Write-Output "Generating SSH key"
ssh-keygen -C john.doe@domain.com -P '""' -f "$HOME/.ssh/id_rsa"
cat $HOME/.ssh/id_rsa.pub | clip
Write-Output "Your SSH key has been copied to the clipboard"
This script will try and install Chocolatey, install key software mentioned in this tutorial, install a couple of Python versions with pyenv, generate your SSH key and present it to you so that you can go to GitHub and add it to your account.
If youβre going to use it, be sure to customize the software you want to install and to swap in your email on the ssh-keygen line.
Make sure the Python app execution aliases are disabled, get the shortened link to the raw contents of the file hosted on GitHub as described in the previous section, and run the following command in an elevated PowerShell session:
PS> Set-ExecutionPolicy RemoteSigned -Force
PS> iwr -useb bit.ly/xxxxxxx | iex
With that, you should be ready and raring to go! The only optional steps left are to configure general Windows settings, maybe debloating and setting up your config files along the way.
Conclusion
Now youβve set up your Windows machine to do some development with Python. Youβve explored some modern tools to manage your software and different Python versions. Not only that, you got a crash course in PowerShell and saw how you might start to automate an installation.
In this tutorial, youβve successfully:
- Cleaned and updated a new Windows install
- Used Chocolatey to bulk install key software
- Used the built-in
ssh-keygento generate SSH keys and connect to your GitHub account - Set up a development environment, including PowerShell Core, pyenv for Windows, Python, and VS Code
- Written a script to automate the process as much as possible.
With this Windows setup, youβre ready to start coding with Python. Since youβre also connected to GitHub, youβre ready to try your hand at contributing to open-source projects, too. In the comments, feel free to share what youβve been working on!
Free Bonus: Click here to get our free Python Cheat Sheet that shows you the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.
Other Nifty Windows Software
Now that you have Windows all set up for Python coding, you may want to make your life even easier. Here are some great Windows utilities that can help you do just that:
- Everything: A great search utility that leverages Windows-only file indexing tools. It can be used as a general file finder and an application launcher. Itβs fast!
- Windows Subsystem for Linux: If you want to have an almost fully fledged Linux experience within Windows, check out WSL. This isnβt a Chocolatey package.
- Autohotkey: An easy-to-use and hugely popular automation tool only for Windows. Some people stick with Windows just for AHK!
With these utilities installed, youβre ready to tackle any coding challenge.






