Some of the commands mentioned here are NVDA-specific. If you would like other screen readers to be included, please send me the list of the navigation key commands and I will update the guide to include the information
As the community began shifting to Python, the same questions got introduced over and over again. How do I run scripts? How do I see errors? Where do I get Python? This guide will aim to introduce the basics of setting up Python and will hopefully go on to some more advanced concepts such as windows, sounds, and speech.
Python can be downloaded by going to python.org and browsing to the "download" heading. Do to the constantly updating nature of the language, no link will be provided as it will probably change. The first link under the download heading should take you to the latest version page. From there it is as simple as choosing what platform you use and downloading the installer.
You don't have to do everything I do, but some of these settings should save you some headache.
A second note
If I did not mention a setting in the installer, it remains at it's default value
Actual installation instructions
First, do not click on "install now" option. Choose custom installation instead.
I like to change my installation directory to something more obvious just in case I want to mess with the python folder, though it ultimately doesn't matter as long as it does not end up in program files on a 64-bit machine (I have been told and have experienced file writing errors because the app didn't have the permission to do so).
Click next, and you should have some more options.
I do not install the Idol, primarily because it appeared not to be accessible when I tried to use it. I do add python to my environment variables to save me some typing, and I do check the box for both associating .py with python and precompiling the standard library, though I am not too sure what the second one does. I have tried using python with and without debugging symbols and could not really tell the difference, so that box is left unchecked, at least on my machine.
You should be good to install python now. After the installation completes, do not delete the installer. If by some chance you screw up your interpreter you can run it and click on the repair option (Saves you from reinstalling everything.)
A quick note
If you have py launcher installed and are planning to run multiple Python versions, do not add python to environment variables. Py launcher provides a quick and a convenient way of launching python by typing py into your command line. Thanks to NicklasMCHD for this tip, I didn't know that
There are two ways to run Python code. The most easiest way is to hit windows R to get into your run dialog and then type in python.
If you are on windows 10 and typing python in the run dialog brings you to the Microsoft store, you must run the command from the command line. Read on how to do so.
Opening Python via Command Line (CMD for short)
To get into your command line, hit windows R and in the run dialog type cmd. This should bring you to the terminal where you can type in commands. Now type python.
What you should see as the result of either step
If everything worked correctly, a window should pop up with 3 greater than signs which signify that python is ready to receive input. Type this into your console:
If you do not hear the message "hello world", make sure that your reporting of dynamic content changes are on by hitting NVDA+5 and run the command again.
When you are ready to quit, typing exit() or quit() should close the console.
Running scripts from files
The console is great for quick and dirty tests, but what if you need to have multiple files in your project? This is a little trickier to do.
Create a blank document.
Type in print("hello World!")
Save your document as hello.py
Open up your command line
Go into the directory where you have saved your file.
If you do not know how to use CMD, cd directory_name takes you to that directory, such as cd desktop, and cd .. takes you back to the previous directory in relation to where you currently are.
For example, the main python folder comes with a folder called lib inside it. If I was in the lib folder and I typed in cd .., I would now be back in the python directory.
A quick tip: If you don't know how to spell something, hitting tab will move you through files and folders within your current directory. After that it is as simple as it is going to be to hit home and type in the desired command before the file name.
Type in python hello.py
If everything works as expected, great! You now are mostly ready to proceed with Python tutorials. If you do not get any output, make sure that reporting dynamic content changes option is on by hitting NVDA+5 and repeat the command.
Last note for file scripts
Sometimes, your interpreter will just exit. No announcements of tracebacks, no weird output, no nothing. This is do to some error in your code that does not fall under the syntactical category. To this day, here are two solutions that I use on the regular bases
Easy to learn, annoying to access
If your program crashes, a good thing is to change your command from
python script.py 2>error.txt
The file extension doesn't really matter as long as you're within reason (I wonder what would happen if you change your extension to mp3?). What the command above will do is capture any errors your program throws and create a file within the program's directory called error.txt in my case with the textual description for that error. The downside is you having to reopen the file every time a new bug is found.
A bit more harder to learn but quicker overall
Another way to see tracebacks is by using your object navigation. First, hit NVDA page up and down until you hear "object review". Whenever a new error is generated, use NVDA and up and down arrows to look through the screen and find your traceback.
I have heard that this method does not work for some people. In that case, use the first method.
A second note
This method is meant to be used in conjunction with the command line.
A Third Note
When you begin scrolling, you will see the error first. Scrolling higher will reveal what exact lines it happened on
How do you deal with indentation
A lot of people hate Python do to it's indentation. However, there is a simple fix for that problem in NVDA.
Open up your NVDA preferences, go to settings/document formatting, and hit alt i. You should be on the indentation report combo box. Choose how you'd like indentation to be reported by using your up and down arrows and then tab to the OKAY button or hit enter to close the settings. Personally, I do speech because I use one-space indents and the tones are difficult to tell apart, but you may be different in this regard.
Great, how can I get started learning the language?
Some tutorials I used are listed below
How to think like a computer scientist, good for starting out but may require creativity with some of the projects
Dive into python 3 (Start with "Your first python program")
Learn python the hard way
Automate the Boring Stuff with Python (Used for a brief time to cement what I knew)
Recently, i have been surprised at the amount of people not knowing how to track down their problem when it comes to chunks of code. Here are some of my strategies and or tips
The most basic thing everyone tends to forget. You always think "I will remember what this convoluted line means a month from now, no need to write a comment." Wrong. I don't mean for you to comment every single line of code, but docstrings or comments at a beginning of functions should do some wonder. If you truly feel the spirit, chunks of logic can be commented as well, though that will require more organization on your part.
I can't stress this enough. Printing can do wonders when you're struggling. Even something like "This is the correct if statement" can help alleviate concern that your program branches into false logic paths. If you are still struggling and your function accepts parameters, start printing them. Make sure that your params are all of the type you expect.
Search before asking!
The benefit of a mainstream language is that whatever you try and do, someone has probably have tried to accomplish the same thing or it's equivalent. If you are getting an error which you just can't understand or have never seen before, paste it into Google (excluding lines, of course). If your error pertains to a variable, such as "Name error: Var is not defined", try to generalize your task, i.e, error when trying to assign a value to a variable in a function or variable stays the same when the function executes. Be sure to stick python or python 3 in your search somewhere to filter out most if not all other language results (I usually add it in at the beginning or the end of the search string). Do not come up here and ask unless the question is conceptual or you have actually tried to solve the problem. You will learn much more searching than you ever would asking on here and getting quick answers. If you are still stuck after searching, you will have more information to share, which would help folks here to help you track down the issue quicker and prevent them presenting solutions that you already have tried.
I am aware of it seeming like it was a lot of information, and that's because it was. However, the later portion of this guide is more aimed at intermediate users rather than somebody who is just getting started. I have also attempted to cover as much as I can so that everybody may have a somewhat centralized list of information they can refer to if they have any issues.
Thank you for reading, and I do hope that you find this useful. If you have tips, suggestions, or improvements which you think are crucial to this guide, please, let me know.
Parts of this guide
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.