5.2. Some Special Windows Instructions

While the Python language changes slowly, operating systems and setup methods change more rapidly with succeeding versions. The attempt here is to keep all such information in one place for the Windows operating system. It may become out of date at any time.

– Last checked this on Windows 10 and Windows 7 with Python 3.7.

5.2.1. Versions

I will use Python 3.8+ to mean the current version of Python, with version number at least 3.8.1. Make sure you have the latest recommended version installed from https://www.python.org/downloads/. Download the Windows version. Read this section before doing any installation. In particular note paragraph below with italics in it.

If the only option is to save it, agree, and find it in your download folder and double click to execute it. If you have an option to immediately run on download, you can choose that.

You are likely to get a security message before running. Click Run.

Pay attention: before clicking on Install Now, note if there are check-boxes at the bottom of a window you see. Make sure both are checked, about the Python Launcher AND to add Python to environment variables.

The final screen that you reach in the installation links to more advanced references than we will want in this course, so probably skip them for now.

Python now behaves differently if you installed a previous version before (like me). I could have missed something for someone installing Python for the first time. Feel free for me to watch you while you share your screen in Zoom.

If you install Python without putting a check mark on Add Python to environment variables, then you can go back and fix it. This is important for Ch 4:

  1. Run the Python installation script again. Since python is already there it looks different when it starts - the first option is modify; click on that.

  2. Just click Next on the second screen

  3. On the following screen is where you make a change: Click to put a checkmark in front of the line saying:

    Add Python to environment variables.

    Then click next/continue/finish - whatever to just advance to the end.

You are encouraged to test if Python did get added to the environment by starting Idle as discussed on the next section.

5.2.2. Starting Idle Shortcut

If you want to start Idle without a starting file, but later deal with files in the examples folder, then a one-step shortcut is to double click on the file IdleOnWindows.cmd in the examples folder. If this does not work (in Windows), then go back and modify your Python installation, as discussed in the previous section.

If you want to do extensive Idle work in another folder, you can copy IdleOnWindows.cmd to there and use it.

5.2.3. File Names in the File Explorer

By default Windows does not display file extensions in File Explorer Windows. You may have multiple files with the same base name but different extensions. Particularly if you want to attach one to an email or homework submission, this can lead to problems.

You are strongly suggested to change the viewing default in File Explorer to show extensions.

5.2.4. Chapter 4 CGI Instructions

You can skip this until you are starting Chapter 4.4 on CGI files. Opening .cgi Files in Idle

By convention the server programs that you will be writing end in ”.cgi”. That is not an extension that is automatically associated with Idle for editing. If you want to open a .cgi file (or any other type but .py) to edit (and never run) from inside of Idle, it is possible to do this directly in many steps, but it is easier to go indirectly:

  • Start a .py file you have in Idle (like localCGIServer.py), or if IdleOnWindows.cmd is there, as in my www folder, use it to start Idle.
  • To open a .cgi file from inside Idle, you select Open form the File menu like normally, but then notice the drop-down choice in the lower right of the file open window that probably shows Python files (.py): Change this file filter to All files (.*).
  • Then all files in the current folder should be listed, not grayed out, and you can navigate to and choose the one you want. Saving a new .cgi file

As with opening a .cgi file, set the format filter at the bottom of the dialog window to All files (.). Then enter the full file name with the .cgi. If you forget and do not change the file filter, a ”.py” will be added to your file name. Then you can rename it in File Explorer. Running CGI Scripts

If you insist on doing cgi work in a different folder, copy both startServer.cmd and localCGIServer.py as well as all related .html and .cgi files to that folder, and then when you want to test your work, start the local server from there with startServer.cmd.

At this point you can do all the web server based activities in Chapter 4. There are a number of steps: be sure you carefully go through the list in the tutorial. Remember, html files calling a cgi file, and cgi files used directly are only run in your web browser with a URL starting with localhost:8080/, and only after you have a local server running from the same folder. Otherwise nothing dynamic happens.