A Beginner's Python Tutorial/Installing Python
What is Python?
editIf you don't understand this, don't worry. Just skip it and move on.
Python is an interpreted programming language. For those who don't know, a programming language is what you write down to tell a computer what to do. However, the computer doesn't read the language directly—there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it—that is, turn it into lots of 0s and 1s, that the computer can easily and quickly understand. A Windows program that you buy is already compiled for Windows—if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go—find a small Windows program, and open it up in Notepad or Wordpad. See what garbled mess you get.
But that Windows program is compiled for Windows—no other machine can run that program, unless it has Windows. What Python is, is a language which is never actually compiled in full—instead, an interpreter turns each line of code into 0s and 1s that your computer can understand. And it is done on the fly—it compiles the bits of the program you are using as you are using them. If you were to quit the program and come back another day, it would compile the bits you are using, as you are using them, again. Seems a waste of time? Maybe, but the fact is that when you come back another day, you might be using a Windows PC instead of a Mac. You might send the program to a friend, who uses another type of computer. Or you might post your program on the internet, where everyone using all different types of systems might download it. That is the wonder of an interpreted programming language—it is like a language that everyone can understand.
How to install Python
editFor Python programming you need a working Python installation and a text editor. Python comes with its own editor IDLE, which is quite nice and totally sufficient for the beginning. As you get more into programming, you will probably switch to some other editor like emacs, vi or another.
The Python download page is https://www.python.org/downloads/. The most recent version is 3.12.1 (as of January 21, 2024), but any Python 2.x version since 2.2 will work for this tutorial.
Python 2 vs. Python 3 Python 3 is the currently supported version of Python with Python 2 being sunset.[1] That said, an understanding of Python 2 can be handy for some work, and for historical reasons. If you follow this version of the book, be careful to operate under a Python 3, environment, as some significant details have changed, and hence this tutorial's examples will not work with it. A version of this tutorial for Python 3 is at Non-Programmer's Tutorial for Python 3. |
There are various different installation files for different computer platforms available on the download site. Here are some specific instructions for the most common operating systems:
Linux, BSD and Unix users
editYou are probably lucky and Python is likely already installed on your machine. To test it type python on a command line. If you see something like that in the following section, you are set.
If you have to install Python, just use the operating system's package manager or go to the repository where your packages are available and get Python. If you are already comfortable with programming and Unix and are here to pick Python 2 up, you can alternatively compile Python from scratch after downloading the source code. If you get the source code make sure you compile in the Tk extension if you want to use IDLE.
Mac users
editStarting from Mac OS X (Tiger) and ending with MacOS 12.3[2], Python shipped by default with MacOS. That said you might want to update to the newer version (check the version and install status by starting python in a command line terminal). Also IDLE (the Python editor) might be missing in the standard installation. If you want to (re-)install Python, you can get it from the Mac download page on the Python site.
Windows users
editSome computer manufacturers pre-install Python. To check if you already have it installed, open command prompt (Windows Key+R then type cmd) and type python. If it says "Bad command or file name" you will need to download the appropriate Windows installer from the Windows download page. If you do not have a 64-bit AMD or Intel chip processor, you will need the Windows x86 MSI Installer; otherwise the Windows x86-64 MSI Installer is the correct one (they are very similarly named, so check carefully which one you are downloading). Start the installer by double-clicking it and follow the prompts.
After installing you will need to add the installation path to the PATH system variable if you wish to use it from the command prompt instead of the IDLE editor.
Windows Store Version The official Python app on the Windows store is for Python 3, and is not compatible with this Wikibook. |
References
edit- ↑ "Sunsetting Python 2". Python.org. Retrieved 21 January 2024.
- ↑ "macOS Monterey 12.3 Release Notes". Apple Developer Documentation. Retrieved 22 January 2024.