Setting up your computer

Two lessons before your first project: how to install Python and a code editor, and how to stop being afraid of the terminal. Commands are given for Windows and for macOS with Linux, pick your system.

If something doesn't work, check the common errors of the first project. Unfamiliar words are in the glossary.

0 of 2 lessons done

NACA laboratory staff working with an IBM 704 computer, 1957
  1. Lesson 1. Installing Python and a code editor

    Why. In the lessons, code ran right in the browser. But your own Flask or Django site runs on your own computer. For that you need two programs: Python itself and an editor that makes writing code comfortable.

    Python. Download the installer from the official site python.org, version 3.12 or newer. Download it only from there: other sites may slip you a virus disguised as Python.

    The most important thing on Windows. On the first screen of the installer, tick “Add python.exe to PATH”, then click “Install Now”. Without this tick the python command in the terminal will not work.

    On macOS install Python with the installer from the same site. On Linux it is usually already there: check with the command below.

    Check the installation. Open a terminal (how to do it is in the next lesson) and run the command from your system's tab. You should see a version, for example Python 3.13.1.

    Code editor. A handy free editor is Visual Studio Code. After installing it, open the extensions section (the icon of four squares on the left) and install the Python extension by Microsoft. It highlights code and points out errors.

    Your first program on the computer. Create an empty folder, for example pyweb, and open it in VS Code: “File → Open Folder”. Create a file hello.py, write print("Hello from my computer!") and click the triangle ▶ in the top right. The result will appear at the bottom, in the terminal.

    Common error: “Python was not found”

    On Windows the python command opens the Microsoft Store or prints: Python was not found; run without arguments to install from the Microsoft Store… This means the PATH box was not ticked during installation. Run the installer again, choose “Modify” and tick “Add Python to environment variables”. Or use the py command instead of python: it is installed together with Python.

    Common error: “command not found: python” on macOS

    On macOS and Linux the command is often called python3, not python. Type python3 --version and python3 hello.py.

    Check yourself:

    • the command from the tab below shows version 3.12 or newer;
    • the Python extension is installed in VS Code;
    • the file hello.py runs and prints a greeting.

    Windows (PowerShell or Command Prompt)

    Terminal: checking the version
    python --version
    py --version

    macOS and Linux (Terminal)

    Terminal: checking the version
    python3 --version
    File hello.py
    print("Hello from my computer!")
    print("Python works.")
  2. Lesson 2. The terminal without fear

    Why. Programmers often control the computer not with the mouse but with commands: they install libraries, start the server, create projects. All of this is done in the terminal. You will need it from the very first step of the first project.

    What a terminal is. It is a window where you type a command in words and press Enter, and the computer runs it and prints an answer. It is very hard to break the computer with it by accident: the commands in this course are safe.

    How to open it. The easiest way is right in VS Code: the “Terminal → New Terminal” menu or the keys Ctrl + `. Separately: on Windows press “Start” and type “PowerShell”, on macOS open the “Terminal” app.

    Where you are. The terminal always works in some folder, and its path is written at the start of the line. Commands run right there. If a program “can't find the file”, most often you are simply in the wrong folder.

    Five main commands:

    • cd folder — go into a folder, cd .. — go one level up;
    • ls (in the old Windows command prompt — dir) — show the files in the folder;
    • mkdir name — create a folder;
    • python hello.py — run a program (on macOS — python3);
    • Ctrl + C — stop a running program, for example a server.

    Two tips that save time. The up arrow brings back the previous command, so you don't have to type it again. The Tab key completes a file or folder name from its first letters.

    Common error: file not found

    The command python hello.py answers can't open file 'hello.py': [Errno 2] No such file or directory This means you are in the wrong folder. Look at the files with ls and go to the right folder with cd. In VS Code the terminal opens right in the project folder.

    Common error: spaces in a folder name

    cd My projects won't work: the terminal will think these are two separate parts. Put the path in quotes: cd "My projects". Even better, name project folders without spaces and in Latin letters: my-site.

    Check yourself:

    • you opened the terminal in VS Code and see the folder path;
    • created a folder with mkdir and went into it with cd;
    • ran hello.py with a command from the terminal, not with the button.

    Windows (PowerShell)

    Terminal: first steps
    mkdir my-site
    cd my-site
    ls
    python hello.py
    cd ..

    macOS and Linux (Terminal)

    Terminal: first steps
    mkdir my-site
    cd my-site
    ls
    python3 hello.py
    cd ..

    Put the hello.py file from the previous lesson into the my-site folder, otherwise the run command won't find it. That is exactly the “common error” from this lesson.

What's next

Your computer is ready. Now you can build your first site: a to-do list on Flask or Django.