Installation and setup
You can complete the first examples in this handbook using your browser. A local Python installation lets you save scripts, use a terminal, and build the multi-file projects in the later chapters.
On this page
Choose your operating system
Follow one installation guide. Each ends with the same check: your own file running inside a local project environment.
Check your interpreter
A terminal is a window where you type commands and read their results. On macOS or Linux, open Terminal and enter the command below.
python3 --versionOn Windows, open PowerShell and enter py --version. Use Python 3.12 or newer for the downloadable course files. If your command already prints a suitable version, proceed to the next section. If the command is missing, install Python for your operating system.
- Windows: Get the Python install manager from Python for Windows. Open a new PowerShell window, use the manager to install a Python 3 runtime, then repeat the version check.
- macOS: Run the macOS installer from Python downloads, reopen Terminal, and check
python3 --version. - Linux: Use your distribution’s package manager to install Python 3 and its virtual-environment support if needed. Check the installed version before continuing.
Create and run a file
Create a folder named python-study. Open it in a text editor and save the following line in a plain-text file named hello.py.
print("My first Python file")Open a terminal in that folder. Run python3 hello.py on macOS or Linux, or py hello.py on Windows. You should see My first Python file. Change the words, save the file, and run the command again.
If Python reports that it cannot open the file, list the current directory with ls or, in PowerShell, dir. Check that the filename is exactly hello.py. If your prompt starts with >>>, you are inside the Python interpreter. Type exit() to return to the terminal before running a shell command.
Create a project environment
A virtual environment gives one project its own Python packages. From the project folder, run these commands on macOS or Linux.
python3 -m venv .venv
.venv/bin/python hello.pyOn Windows, use PowerShell.
py -m venv .venv
.\.venv\Scripts\python.exe hello.pyThe first command creates the environment. The second runs the script with that environment’s interpreter. The standard library is already available. Later, use this same interpreter with -m pip install when a project needs a third-party package.
Use the example files
Download the example files, extract the archive, and open the python_from_zero folder in your editor. Each numbered lesson includes a demonstration called lesson.py and an exercise answer called solution.py. The final project also includes its package and tests.
To run the first example from the extracted folder, use the following command. On Windows, replace python3 with py.
python3 01_foundations/01_start_here/lesson.pyDiagnose a setup problem
| What you see | What to check |
|---|---|
A command gives SyntaxError after >>> |
You are typing a shell command inside Python. Enter exit() and repeat it at the terminal prompt. |
| Python says it cannot open your script | Run pwd and ls on macOS/Linux, or Get-Location and dir on Windows. Open the folder containing the script and check its full filename. |
| A package installed successfully but import fails | Compare the interpreter printed by import sys; print(sys.executable) in your editor with the project interpreter. Run that project interpreter with -m pip --version to see where its packages live. |
| The tests report zero tests | Run from the folder containing study.py and test_study.py. Test filenames and methods in the example start with test_. |
Once your script runs, build and test the study-time calculator.