Some Special Current Windows Instructions

I have checked this on Windows 10 and Windows 7.

This document supersedes any conflicting instructions in the tutorial itself. As versions of Python and operating systems have changed, some old usage instructions get out date, and it is easier to maintain all such changes in one focused document.

Versions

I will use Python 3.6+ to mean the current version of Python, with version number at least 3.6.1. Make sure you have the latest recommended version installed from https://www.python.org/downloads/. Download the Windows version. 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: On the first screen, before clicking on Install Now, note the two check-boxes at the bottom of the window. Make sure both are checked, about the Python Launcher AND the PATH.

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.

Your Login ID

The normal place for you to have my examples folder is under your home folder, which has the same name as your Login ID. If you are just creating a login ID, it will save some hassle in Chapter 4, if your login ID does not have a space in it. "Andy" or "anh" or AndyHarrington" would be fine for me, but

"Andy Harrington"

would bomb the server in Chapter 4.

If You Have a Blank in your Login ID

The local server program central to chapter 4 bombs with folder paths with a blank in the name.

If you have a blank in your Login ID, it is not so easy to change. Instead make a folder outside of your home folder:

  1. In the File Explorer go to This PC or Computer and select C: drive.
  2. Create a new folder and give it a name without blanks, like comp150. I suggest that you move my examples folder, or just the sub-folder www so it is under your new folder. For Chapter 4 test my examples and add your work there.

Folder For My Examples

Wherever you plan to unzip my Python examples folder from http://anh.cs.luc.edu/python/hands-on/3.1/examples.zip you need to make sure that my www folder, and any other folder where you put later .cgi files does not have a blank in its name, or any folder in which it is a sub-folder. If you have a "comp 150" folder, you might rename it "comp150".

Running VS. Editing

Python files can be either run or opened for editing.

Editing by Default

You will be working mostly with files ending in .py -- Python source files. Most of the time you will be editing them and running them in IDLE, so the best default behavior when opening a file with extension .py is to have it open in Idle 3.6+.

To open a python file from the File Explorer window with Idle

  • You may be able to double click on the file in Explorer (or that may execute the program, and then likely have its window immediately disappear)
  • If that is not set right, right click on the file, select Edit with Idle, and click on the sub-menu for Idle that opens.

Idle can also be opened by going to All Programs with the Windows Start menu, opening Python 3.6+, and selecting Idle. This is OK if you just want to play with the Python shell window. If you want to open or particularly if you want to save a file there is the major disadvantage of the current folder being the Python system folder. Saving a file with the wrong name there can totally screw up Python (and has - and has been awful to debug).

For earlier versions of Python on Windows (3.4), the tutorial still refers to a shortcut for opening Idle. Such shortcuts do not work in 3.5 or 3.6. Ignore the file and any description of it, and use the methods above to open a Python file.

Inside IDLE

Opening/Creating Files from Inside Idle

You may select Open in the File menu inside Idle, either with the Shell window or a file editing window as the active window. The folder that it expects the file to reside in depends on the window you started from:

  • If your current window is a file editing window, the folder that you see will when you go to open a file is the same folder as the current file.
  • If your current window is the Python Shell window, and you opened it from the Start Menu as discussed above, then be very careful! The associated folder is the Python system folder, and you can get really mess things up trying to save a file there! Be sure to change to a folder you control.

Behavior is similar if you go to the File menu inside Idle to create a totally New file: when you go to save it later, the folder you will see will be selected just as when you opened a file above.

Saving Files

If you have modified a file and want to save it under a new name, make sure the file is in the active window (you are not in the shell window), go to the File menu and Save. It is easiest if you save all files in the same folder: my examples folder (except in Chapter 4).

Running Program Files

Make the Edit window for the file you want active by clicking in its window, then go to the Run menu and select Run Module. Note the F5 shortcut key.

Chapter 4 CGI Instructions

You can skip this until you are starting Chapter 4.4 on CGI.

Remember this is the time when it is critical not to have .cgi files under a folder with a blank in the name. See the earlier discussion.

CGI Files on My Server Do Not Work!

The administrators of my server changed the security parameters, so now the links to run cgi scripts on my internet server do not work. Just use the ones for the local server on your machine, as discussed below, starting with localhost:8080/.

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 directly in many steps, but it is easier to go indirectly:

  • Start a .py file you have in Idle (like localCGIServer.py) (or go from the Windows Start menu)
  • 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 it to All files (.*).
  • Then all files in the current folder should be listed, and you can navigate to and choose the one you want.

Running CGI Scripts

If you create and edit a cgi file inside Idle, remember you cannot run it from inside Idle. Besides editing there is one thing you can and should do after editing: be sure to check the syntax, using alt-X, or else you will get zero feedback on syntax errors.

When you want to test a cgi script, you first need to have launched the local CGI Server. Note that localCGIServer.py can be run from inside Idle, but then running any other program inside Idle kills the local server.

You can also start the local server and keep it running as long as you want to run .cgi files in that same folder, by double clicking on startServer.cmd which I have placed in the example www folder. (Note there is a separate Mac/Linux file, cgiServerScript: do not try to use that!)

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.