1a. Inside the Mind of Software – Python How-To Guide

Reading Time: 7 minutes

As a beginner, you will want to start out following these instructions:

1. Using an online “Python in your browser” service such as PythonAnywhere in order to be able to run code interactively, which essentially means you can type and execute a single line of code, one after another, and therefore test your code as you go along.

2. With Python running in your browser, begin to put Python code in a file, of which we will call a script. Then attempt to run that script.

3. Proceed to install Python on your computer.

4. IPython and Jupyter are good programs to consider for installing, which are interactive development environments or IDE’s that can be used to run Python as well as other programming languages.

We will provide you further details on how to achieve these instructions down below. If you have some advanced level of familiarity installing applications and whatnot on your computer, you can skip directly to instruction number 3. Otherwise, read from the beginning.

INSTRUCTION 1: Python running in a browser tab, in an online interactive development environment.

As was stated previously earlier in the article, there are several websites that allow you to run Python in your web browser. You can run any of these that you please, but the detailed instructions will pertain to PythonAnywhere.

First, go to Pythonanywhere.com and click the “Pricing and Sign Up” page on the top menu bar, in the upper right corner of the homepage. The free beginner account will be sufficient for our purposes.

Second, once you create the account, there should be a sub-tab underneath with the name “Consoles”, which is where you can execute Python commands. The other consoles enable you the ability to execute other types of commands.

Third, where it says, “Start new console”, select Python 3.4, which will launch a fresh console running Python on version 3, which is the current version. The result should be a black window with some harsh looking font of white letters against the black backdrop.

In the black window, you will notice it contains information regarding the Python interpreter as well as the operating system it’s being run on. The next line should contain something called a “prompt” which will provide you with an indication as to the state of readiness of the usability in terms of writing Python code there. You can type any of the examples that we will provide you with and see the results for yourself, as the interpreter will interpret the code in these examples and execute them accordingly.

Fourth, you should click the “Dashboard” tab in the upper right menu, and you’ll see a new console has popped up under the “Consoles” subtab. Then in order to return to your console, click on it’s name, it should say something like “Python 3.4 console 1724197”. These consoles can be kept active for as long as you desire, but if you wish to clean them up and delete them, you can press the “kill” button located beside them.

Fifth, this step is more optional than mandatory but if you prefer, you can nominate this website as your “teacher” on PythonAnywhere. If you have any questions, you can always refer to the Python documentation or to the W3 Schools website for more in depth tutorials and explanations. If you nominate this website, we will have access to the consoles and files you create on PythonAnywhere, although it will NOT grant us access to your computer. If that is something you would consider doing, navigate your cursor to the “Account” tab in the menu bar and then proceed to the “Teacher” subtab.

Enter the username of this website, “MethodologyDesign”, in the text box, then click the check button. Our team should receive an email that you’ve signed up.

Sixth and final point, click on the “Dashboard” tab and proceed to choose an open console or make a new one, and return to trying different examples and codes you can find around the internet to see what they produce.

INSTRUCTION 2: Running Python in your browser, using scripts.

If you intend to run Python interactively, it can be a good learning experience for beginners. It can be a however, somewhat of a clunky experience, especially if you intend to write more than just a few lines of code.

An intelligent way would be to make use of a file called a script in which the commands are already written down but are then fed into the interpreter in order to attempt to execute all or some of these commands. Here are some basic instructions on how to carry out this task in PythonAnywhere:

The first step is to click on the “Dashboard” tab and then proceed to click on the “Files” subtab. You should be able to see a list of files that were created by the system.

The second step is to navigate to the text box that says “Enter a new file name”, and then type a name like Myprogram.py. It is customary in the Python language that files written in Python end with the extension .py. Click the “New” button, and there should be a prompt where you can write stuff. Let’s call the prompt a sort of editor. When you want to run your code, click on the button with the three angle brackets, that look like this – >>>. If it’s your first time doing this, there’s a good chance your browser will ask you to allow popups, in which cash you should click yes.

If your program executed successfully, you will get the result of your work in this new popup. Now you can edit and execute the program as many times as you wish inside this popup.

In the third step, when you are finished, close the window that gave you your output and proceed to return to the “Files” tab. The file that you created when you executed the script should now be in that list of files, automatically generated for you. You can now proceed to use the buttons to either download, edit or delete the file.

If you return to the “Console” subtab, there is a slight possibility that there might be a console for the file you just finished editing. When you have completed the file to your satisfaction, you can kill the console but the file will remain there for you to reopen again in a new console if you wish.

INSTRUCTION 3: A computer based installation of Python.

The highest recommended software distribution package for Python on the Windows, Linux and Mac operating systems is Anaconda. It also includes the most common Python modules that are used, and therefore you are most likely to use them due to the nature of their utility. The upside to this distribution is that not only is it free, but it’s also an easy install that’s automated for you, requires no manual tasks and installs to your home directory, therefore there is no need to manually grant it administrative privledges.

First, start up your browser, any browser, whichever browser you use, and head on to the Anaconda download page on their website.

Second, in the upper right corner there should be a button that allows you to choose Python 3.4. Click that.

Third, make sure you get the installer that is designed for your operating system, which will most likely be a 64 bit operating system unless you have a computer that is noticeably very old.

Fourth, the software should download automatically. When it finishes downloading, you should proceed by opening it, unless it starts up by itself.

Fifth, the setup wizard will then request input from you as to what options you want in your installation configuration. You will most likely accept what’s considered default by the software and proceed that way. It is recommended that you allow the installer to determine your installation path as well as your search path and to find any older verisons of Python that may be slithering around your computer, which Anaconda is programmed to do.

Sixth, from the start menu included in the program, look for a button called “idle” which provides you with a programming environment that is the default, most commonly included programming environment, simplistic and basic, included with the vast majority of Python distributions. When you fire up IDLE, you should see a window before you that consists of a “shell” or a sort of command prompt, that is utilizing a Python interpreter to understand your commands. This is where you can type and execute your Python compatible statements.

Seventh, you will want to write a script. Begin this by going to New in the File menu, in order to create a new script file. Insert some Python code and then click Save from the File menu. Proceed to pick a name for your file and then save it to a location in your home folder, which is usually the default installation folder of Anaconda, or the location could be automatically set to point to the script folder within Anaconda’s directory.

Eighth, you can execute the script by selecting the Run Module field in the Run menu, or by pressing F5 on your keyboard. If the code executed properly, you should now see the fruit of your labor before you. If not, then there will be some error messages to guide you as to what went wrong.

As far as troubleshooting goes, if you’ve already installed a previous version of Python on your computer, there is a good chance you will run into some compatibility or conflict issues when attempting to run an old version of the software by accident as opposed to the fresher version. In order to see if everything is fine, try to run Python or IDLE and see if you can check the version information for what you’re running. It should be written there for you to see. You should be able to see some version of Python 3, and some version of Anaconda 2. If you don’t see either of these, then you are most likely not running the latest version that we’ve instructed you to install. With a little bit of searching, you might have some success in finding the right shortcut that is used to launch the right and more recent version of Python. In case you don’t figure this out, you can always attempt to reinstall the software and either change the path or have the installation package figure out the path for you.

INSTRUCTION 4: Operating Jupyter.

If you installed Python with Anaconda, and chose the default installation values, then it is very likely that you also installed Jupyter, which is an interactive development environment or IDE for short, that can be used with Python as well as other programming languages. Until some time ago, Jupyter was referred to as IPython, so you might see that name pop up here and there.

Going to the start menu, look for Jupyter. The search results will most likely yield several choices, including:

– Jupyter has a Python interpreter embedded in it’s launch module and by default comes with supplemental features that you might find useful.

– Jupyter QTConsole actually has a Python interpreter that is displayed to you in a sort of graphics based environment over purely a text based one.

– Jupyter Notebook will boot up Python but it will run in a browser as opposed to as a desktop application.

In that case, Jupyter Notebook comes highly recommended. In order to launch Jupyter Notebook, open up the command line and type:

s jupyter notebook

You can find additional material on Jupyter’s website regarding Jupyter Notebook here: https://jupyter.org/documentation