September 10, 2021

Python on Windows

I am almost exclusively a linux user. I am interested in exploring python on windows as a way of writing software that I can distribute to friends who only have windows machines.

My windows "test bed" is a machine running Windows 10 with the latest updates as of September 2021. I jump on it, fire up a command prompt and try several things:

vi - does not work
vim - works (I should set up a "vi" alias somehow)
python - launches python 3.8.4
Finding python 3.8.4 is a bit of a surprise. It is dated July 13, 2020 -- so it is barely a year old. I wish I remember how I installed this. I was working on WSL (windows system for linux) back around then, but I hardly think this got installed as part of that, but who knows.

Installing the latest Python (3.9.7)

My up to date Fedora system offers me Python 3.9.6 and the windows instruction indicate that Python 3 installers for Windows are available. Here is what I do:
Launch chrome on my Windows machine.
Use google to search "python for windows"
Go to the "Python releases for Windows" page
Click the "latest python release" link (python 3.9.7)
At the bottom of the page select:
 Windows installer 64 bit (27.6 Mb download)
I click on the download to start the installer.
There is no "update" option, so I select "install now"
I click the box to "add Python 3.9 to my path"
This goes to C:\Users\Tom\AppData\Local\Programs\Python\Python39
I give my root (admin) password to allow the install
Once this is done, I can type python and get 3.8.4 and if I type "py" I get 3.9.7. This is hardly a good thing, so I'll have to figure out how to get rid of 3.8.4

It tells me it will install PIP as well as Python libraries.

Uninstalling the old Python (3.8.4)

The last thing I want is two versions of python on my machine and endless confusion about which one I am using. The advice is as follows:
Type control panel into the search entry at the bottom of the screen
Launch control panel
Click "uninstall a program" under "Programs"
Scroll down and find both 3.8.4 and 3.9.7 in the list
Select 3.8.4, the uninstall immediately begins
I also find "Python tools 2.2 for Visual Studio 2015" in the list and uninstall that as well. After this I am left with Python 3.9.7 and "Python Launcher"

Using the command prompt, I type "python" and I get Python 3.8.10!! What the heck?

What is up with this Python 3.8.10 ?

I type "where python" at the command prompt and get:
C:\Users\Tom\AppData\Local\Microsoft\WindowsApps\python.exe
Some searching indicates that I need to actually go into this directory and delete the executables. I find I cannot access these as user "Tom", so I signin as "root" -- but windows won't let root access /users/tom.

After I log back in as Tom, typing "python" now gives me 3.9.7. Very confusing, but all is well that ends well.

Typing "where" shows both pythons, but apparently my path hits the 3.9.7 first and gets it, which explains why I am now getting what I want and expect, but the 3.8.10 is still lurking and waiting to cause trouble.

Running python scripts on windows

So far, I have not figured out how to make a script named "hello" run. If I rename it to "hello.py" it gets run (a window briefly pops up and vanishes). To run a script that writes to stdout and see the output, the only thing I have found that works is typing "python hello.py".

Git for Windows

This is by no means python specific, but is critical to how I intend to work, namely developing on linux, then deploying developed code to my windows machine. It looks like this is as easy as downloading and installing.
Do the usual browser search for "git downloads" or "git for windows".
Go to the download site (link below).
Select the windows download link (the download is about 48M).
I will get version 2.33.0
Select and run the downloaded exe file
Answer approximately 1 million questions (with recommended defaults).
I elect to add desktop shortcuts
Supply your root/admin password and stand back
Apparently Git for windows is over 200M in size and includes its own bash and ssh and heaven knows what else. After the install I now have a desktop shortcut called "Git Bash". After I log out and back in again, I can type "git" at the usual windows command prompt and voila! Git shows me the usual help stuff.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org