Install Python & Set Up
You can learn the basics of Python in this browser, but real projects run on your own computer. In this lesson you will install Python, check that it works, try the interactive prompt, run your first .py file and set up a good free editor.
The steps take about fifteen minutes. If something goes wrong, the "Common mistakes" section near the end covers the problems learners hit most often.
Is Python already installed?
Open a terminal: the text window where you type commands. On Windows, open "Terminal" or "PowerShell" from the Start menu. On macOS, open "Terminal" from Applications > Utilities. On Linux, press Ctrl+Alt+T on most desktops.
Type this command and press Enter:
python --versionPython 3.15.0
If you see a version number that starts with 3., Python is installed. On macOS and Linux the command is usually python3 --version, because plain python may not exist there. If you get an error such as "command not found" or "not recognized", install Python using the steps below.
Install on Windows: the Python install manager
On Windows, the recommended way is the Python install manager, a small tool from python.org that downloads and manages Python versions for you. Get it from the Downloads page at python.org (it is also in the Microsoft Store as "Python install manager").
After it is installed, it gives you the py command. Use it to install the latest Python and to see what is on your computer:
py install 3.15
py listNow py and python both start Python 3.15. If you ever need an older version for a project, py install 3.14 adds it alongside, and py -V:3.14 runs that version.
Install on macOS and Linux
macOS: download the macOS installer (a .pkg file) from python.org and run it. After installing, use python3 in the terminal. Your Mac may already have a python3 from Apple's developer tools, but it is often an older version, so install the current one. If you already use Homebrew, brew install python also works.
Linux: almost every distribution ships Python 3 already, because the system itself uses it. On Ubuntu or Debian you can make sure it is there with:
sudo apt install python3
python3 --versionYour distribution may not have the very newest Python yet. That is fine for learning. When a project needs a specific version, the uv tool described below can install it for you without touching the system Python.
The REPL: Python's interactive prompt
Type python (or py on Windows, python3 on macOS and Linux) with nothing after it. You enter the REPL, which shows a >>> prompt. Type any Python line and it answers straight away:
>>> 18 * 12
216
>>> "Rohtak".upper()
'ROHTAK'
>>> exitNotice that the REPL shows the value of an expression without print(). That only happens in the REPL; in a .py file you must call print() to see anything. Type exit (or press Ctrl+D on macOS and Linux, Ctrl+Z then Enter on Windows) to leave.
Since Python 3.13 the REPL has colours, lets you edit multi-line code with the arrow keys, and accepts exit without brackets.
Run a Python file
The REPL is great for experiments, but programs live in files. Make a folder for your practice, for example python-practice, and create a file in it named hello.py with this code:
name = "Ananya"
marks = [78, 85, 91]
print("Hello,", name)
print("Average marks:", sum(marks) / len(marks))Hello, Ananya Average marks: 84.66666666666667
In the terminal, move into the folder with cd and run the file by giving its name to Python:
cd python-practice
python hello.pyUse py hello.py on Windows or python3 hello.py on macOS and Linux if python does not work there. Python runs the file from top to bottom and then returns you to the terminal.
Set up VS Code
You can write Python in any plain text editor, but a code editor helps a lot: it colours your code, spots mistakes as you type and runs files with one click. Visual Studio Code (VS Code) is free and popular.
- Download VS Code from code.visualstudio.com and install it.
- Open the Extensions view (Ctrl+Shift+X), search for "Python" and install the extension published by Microsoft. It also installs Pylance, which gives smart suggestions.
- Open your practice folder with File > Open Folder.
- Press Ctrl+Shift+P, type "Python: Select Interpreter" and choose Python 3.15.
- Open
hello.pyand click the Run button (a triangle) at the top right. The output appears in the terminal panel.
A quick word about uv
As you move on to real projects, you will meet uv, a fast tool that installs Python versions and manages project folders and their packages. You do not need it for this course's basics, but here is a taste:
uv python install 3.15
uv run hello.pyYou will learn about packages, pip and project environments in pip & Virtual Environments.
Common mistakes
- "python is not recognized" on Windows. Python is not installed yet, or the terminal was opened before installing. Install it, close the terminal and open a new one. You can also try
pyinstead ofpython. - Typing terminal commands inside the REPL.
python hello.pytyped at the>>>prompt gives aSyntaxError. Leave the REPL withexit, then run the command in the normal terminal. - Naming your file after a module. A file called
math.pyorrandom.pyin your folder hides the real module of that name and causes confusing errors. Choose names likemy_maths.py. - Saving the file somewhere else. If Python says it cannot open the file, check that the terminal is in the same folder as the file. The
cdcommand changes folder.
Key points
- Check your installation with
python --version(python3 --versionon macOS and Linux). - On Windows, the Python install manager gives you the
pycommand:py install 3.15,py list. - On macOS use the python.org installer; on Linux use the system
python3or your package manager. - The REPL (
>>>) runs one line at a time and shows values withoutprint(). - Save programs in
.pyfiles and run them withpython file.py. - VS Code with Microsoft's Python extension is a good free editor;
uvis a fast tool for projects.
Exercise
Install Python and check the version in a terminal. Then create a file named about_me.py that prints your name on one line and your city on the next line. Run it from the terminal. Finally, open the REPL and work out how many minutes there are in a week.
Show solution
print("Rohan")
print("Pune")python about_me.pyIn the REPL, typing 7 * 24 * 60 shows 10080. The REPL prints the value of an expression by itself, while the file needs print().
Quick Quiz
1. Which command shows the installed Python version?
python --version (or python3 --version on macOS and Linux) prints something like Python 3.15.0.
2. On Windows, which command installs Python 3.15 with the Python install manager?
The install manager provides the py command, and py install 3.15 downloads that version.
3. You type python hello.py at the >>> prompt and get a SyntaxError. Why?
The >>> prompt means you are in the REPL. Exit it and run the command in the terminal.
4. What happens if you type an expression like 5 + 3 in the REPL?
The REPL evaluates each line and prints the value of an expression automatically.
Learn Python with a mentor
Free lessons get you started. Our Python Programming training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
