A step-by-step guide to putting Python on your own computer. You check what you need, install it on Windows, macOS or Linux, write a program as a file, and run it from an editor and from a terminal. A last lesson lists the problems that most beginners meet, with the way out of each one, and shows what to do next. You can skip this chapter and still follow the rest of the book.
4 lessons, about 2 h4 simulations13 problems8 practice questionsPython in every lesson
You do not have to install Python to learn it here, because the code boxes run in your browser. Install it when you want to keep programs as files, work without the internet, or use the tools of professional programmers. Python needs a recent Windows, macOS or Linux system, a few hundred megabytes of space and an internet connection for the download. On a school computer, ask first. A Chromebook can use its Linux environment, and a phone is easiest with the code boxes.
The official place to get Python is python.org, on the Downloads page. On Windows, open the installer, tick the box Add python.exe to PATH on the first screen, and press Install Now. On macOS, download the installer and press Continue through the steps. On Linux, Python 3 is usually already there, and if not, install python3 and idle3 with the package manager. Check the installation by typing the version command in a terminal: py --version on Windows, python3 --version on macOS and Linux.
A Python program is a plain text file whose name ends in .py, such as hello.py. Write it in an editor such as IDLE, Thonny or Visual Studio Code. In IDLE, choose File, New File, type the program, save it, and press F5 to run it. In a terminal, go to the folder with cd and run python hello.py on Windows, or python3 hello.py on macOS and Linux. Check that the file name does not end in .txt, and remember that input() waits for an answer in the terminal.
Most problems of a beginner are about the PATH, the folder, the file name, or the version, and each has a short check. Errors in a file are read in the same way as in a code box: from the last line, with the line number. The tool pip installs packages that other people wrote, and a package is used with import. After this chapter, a learner can keep programs as files, run them, and add packages, and can go on with the rest of the book on a computer or in the browser.
Log in to join the discussion.
Loading…