Installing Python on Windows 10


Got to https://www.python.org/ and hover over the ‘Downloads’ section. You should see the latest version of Python for Windows being suggested to you:

Click on the the grey button as seen above. It will automatically start downloading the .exe installer. Make sure you save the installer to your computer and not just ‘run’ it immediately, as being able to run the installer after you’ve installed can be useful in a number of later situations, viz.:

  1. Modify your install by adding features;
  2. Repairing it, if it breaks; and
  3. Uninstalling.

Once it’s downloaded and you know where it is (usually your Downloads folder), open up Windows Explorer and double-click on the .exe.

This will begin the installation process where you’ll be greeted with the default installer options:

There are a few things to note here:

  1. You get the choice to “Customize” your install or go with the default “Install Now”.
  2. The box “Install launcher for all users (recommended)” is ticked. This “launcher” is the Python Launcher for Windows utility (PEP 397). It is a binary executable, py.exe, that can be used to run scripts instead of python.exe. The Python Launcher for Windows comes “recommended” but you don’t actually need it if you plan on only ever having one version of Python installed on your machine – ie. uninstalling an old version(s) before installing any new version. If you untick the box, you’ll notice the little blue and yellow shield disappears. This is because the default location for installing py.exe is C:\WINDOWS. As this is a restricted directory, you need admin privileges to install it, and the little blue and yellow shield is telling you this. If you don’t have admin privileges on your machine, untick this option. Even if you don’t have admin privileges you can still install the Launcher if you go down the “Customize installation” path (which I go through, below).
  3. The box “Add Python 3.9 to PATH” is unticked. This is because the default install assumes you will use py.exe rather than python.exe. If you have unticked the “Install launcher” option and you’re not going to choose “Customize installation”, make sure you tick “Add Python 3.9 to PATH”. If you’re going to customize you’re install (see below) then you’ll get another chance to ensure the path to python.exe is in your PATH environment variable.

If you’re happy with the defaults, go ahead and click “Install” and the installer will complete the install for you. In such a case, you can stop reading now. From hereon, I’ll be discussing the custom install options.

Custom Install

To perform a custom install, I recommend ensuring that both of the boxes discussed above are unticked before you click on “Customize installation” to go into the next screen that shows your install options:

Documentation

My PC is constantly connected to the internet so I use the Python.org website for any Python documentation. I’ll untick the box.

pip

pip.exe is the Package Installer for Python. The Python install comes with the Standard Libraries but, quite often, you’ll want to install additional libraries. pip helps you install and manage these additional libraries. You’re going to need this so keep the box ticked.

tcl/tk and IDLE

I won’t be developing any GUIs with Python and I won’t be running any, either, so I don’t need tcl/tk. Nor will I be using IDLE – the integrated development environment offered by Python.org. When I first began using Python, I did start with IDLE but then moved on to PyCharm and then VSCode. Now I use Notepad++. Your choice of IDE is up to you, but I’m unticking the box.

Python test suite

This option adds the “unittest” library to your install. I prefer to use pytest so I’m unticking the box.

py launcher

This is the Python Launcher for Windows that I discussed previously. Again, I don’t need it so I’m unticking the box.

for all users (requires elevation)

Tick this box if you’re installing py.exe and you want it installed to the default, C:\WINDOWS, directory. If, instead, you want it installed to a separate “Launcher” directory next to where your Python is installed then leave it unticked.

My install looks like this:

Click on “Next” to view the final options for custom installation.

Install for all users

You’ll need admin privileges if you tick this box. Ticking will also change the “Customize install location” at the bottom, to put Python into your “C:\Program Files” directory so that each user on your machine can use it. I leave my unticked as I like to run my apps will the minimal permissions they need to run. If I encounter a situation that requires elevated privileges then I want to be prompted for permission then and there. Unless you have a valid reason for ticking it, I’d leave this box unticked.

Associate files with Python (requires the py launcher)

If you install the Python Launcher for Windows, then ticking this box will invoke py.exe if you have any Python files you’ve created (with a .py extension) that you want to run by double-clicking on them in Windows Explorer. I won’t be using the Python Launcher for Windows so I’m leaving this unticked.

Create shortcuts for installed applications

This adds items to your Start Menu so you can start Python from there, if you wish. I’d recommend keeping it ticked as it makes life simpler.

Add Python to environment variables

If you ticked “Add Python 3.9 to PATH” on the very first installer page (see above), then this will be ticked. If you didn’t and (like me) you’re not installing the Python Launcher for Windows, then you will need to tick this box. Doing so adds the location of the python.exe binary (shown in the “Customize install location” box) to the PATH environment variable. This way you can just invoke “python” (or python.exe if you wish) at the command line, instead of having to type out the full path every time.

Precompile standard library

Ticking this will increase the time taken for the install but will save you time later whenever you call any of the standard library objects. It’s up to you what you want to do.

Download debugging symbols

Used for debugging at a low level. I leave it unticked.

Download debug binaries (requires VS 2017 or later)

As stated you’ll need Visual Studio 2017 or later installed on your machine to use this. I’m leaving it unticked.

Finally, my install looks like this:

Clicking on “Install” will now install Python on your machine in the Customize install location.

Post Install Checks

You should run some commands to check things are installed properly:

You’ll see both python.exe and pip.exe are the versions you installed and in the locations you installed. You’ll also see the PATH environmental variable now includes 2 new entries:

  1. C:\Users\<user>\AppData\Local\Programs\Python\Python39\Scripts\
  2. C:\Users\<user>\AppData\Local\Programs\Python\Python39\

If you installed the Python Launcher for Windows and you didn’t “install for all users”, you’ll also see another entry in your PATH:

  • C:\Users\<user>\AppData\Local\Programs\Python\Launcher\

If, however, you installed it “for all users” it’s been installed to C:\WINDOWS which was already in your PATH.

If you check your Start Menu, you’ll see icons for what you’ve installed:

As I didn’t install IDLE, I don’t get the icon for launching IDLE. Instead, I only get the iconf or the command line interpreter (as shown).

That’s the install completed. Happy coding in Python!

A note about the Python Launcher for Windows

The Python Launcher for Windows (“the Launcher”) was released in Python 3.3.0. It is actually two binaries:

  1. py.exe
  2. pyw.exe

The latter is invoke for Python files with a .pyw extension. These are applications written in Python that have a graphical component to them. 99% of the time you’ll invoke the other binay, py.exe, to run your Python scripts.

The Launcher was created to make like simpler for developers who use and/or run multiple versions of Python on their machines – something they may have been/are doing with the Python installed on their other OS (viz. *NIX). The Launcher accepts command line arguments that allow a developer to specify which version of Python to run the script on. If not specified, it defaults to the latest release on your machine, so running scripts with:

py.exe <script name>.py

will ensure they run on the most up to date version of Python that you have installed. This way, if you ever install an older version of Python (for example, to run an old script that needs a certain version), py.exe will continue to use the most up to date version unless you specify the version you want it to use as an argument to the py.exe call.

If you don’t install the Launcher then you need to make sure you add the path of python.exe to your PATH environment variable – unless you want to laboriously type out the full path of python.exe every time you want to invoke it (who does?).

The simple rule is: if you’ve install the Launcher, then always call “py.exe” and not “python.exe”. Only call the latter if you’re comfortable knowing exactly what you’re doing.

Categories:Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: