Trouble With Python

From Lupyan_Lab_Wiki
Jump to: navigation, search


Quitting a stuck experiment

If you need to manually quit the study, try, in order:

  1. Control-C
  2. Alt-Tab until you bring up the command window, then Control-C
  3. Ctrl-Alt-Del to bring up the task-switcher, then select python (or pythonw) and 'End Task)

Reporting a python error

When a python experiment is crashing for some unknown reason, and you are writing an email informing the lab or the main experimenter of the problem, it’s particularly helpful to include the error message python is throwing. This will help the main experimenter or possibly other python aficionados narrow down the problem quickly. However, when running the python script in the standard way (i.e. double-clicking on the “.py” file or shortcut), the command prompt closes automatically after running the .py file, so the error message won’t stay on the screen. What you need to do is open the .py file in the command prompt and then copy the error message that appears.

Open the windows command prompt

One way to open the command prompt quickly is to click on the Windows Start Icon/ Image at the bottom left of the screen and enter “command prompt” (without parentheses) in the “search programs and files” box, then hit ENTER.

Open command prompt

Identify the file's directory

To open the file in the command prompt, you need to navigate to the file’s directory. This is like entering the path that leads to (or ‘uniquely identifies’) the file within the computer’s file system. If you have no idea what your file’s path is, you can right-click on the file, go to “Properties" and the file’s path will be specified under “Location.”

Find file path

Navigate to and run the python experiment script (.py file)

Now, to navigate to this directory, you need to use the “cd” command (“change directory”) and enter the path in the command prompt. You can either enter “cd” and then the entire path (in this example, “cd Dropbox\LupyanExps\SLC\SLC”, or you can enter each directory change step for step (e.g., “cd Dropbox”, hit ENTER, then “cd LupyanExps”, hit ENTER, etc.). If you hit TAB, you can navigate through all of the possible options at each branching point along the path (so you don’t need to worry about typos, for example).

Navigate to directory

Once you have maneuvered to the correct directory, enter the file name (e.g. and hit ENTER to run the script.

Run script

Now, the experiment should run as it always does, so enter experimental variables as you always would, etc.

-- Copy the error message == This time, when the experiment crashes, the command prompt will remain on the screen. You will probably see some lengthy text appear underneath the command that ran the experiment. Copy ALL of this text and paste it into the troubleshooting email you are sending to the group. Copying text in the command prompt is strangely tricky, but here is what you do:

  • Click on the command prompt icon at the top left of the command prompt window. A drop-down menu will appear.
  • Go to “Edit” and then “Mark”. A flashing cursor will appear in the command prompt window.
  • Drag your mouse across the entire text that you would like to copy.
  • Then hit ENTER. You have now copied the text and can paste it anywhere, such as into the body of an email (Woohoo!).