Install Python & Set Up

Python · Lesson 2 of 56 8 min read Updated

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:

Terminal
python --version
Output
Python 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:

Terminal
py install 3.15
py list

Now 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:

Terminal
sudo apt install python3
python3 --version

Your 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:

Text
>>> 18 * 12
216
>>> "Rohtak".upper()
'ROHTAK'
>>> exit

Notice 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:

PythonRun it yourself
name = "Ananya"
marks = [78, 85, 91]

print("Hello,", name)
print("Average marks:", sum(marks) / len(marks))
Output
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:

Terminal
cd python-practice
python hello.py

Use 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.

  1. Download VS Code from code.visualstudio.com and install it.
  2. 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.
  3. Open your practice folder with File > Open Folder.
  4. Press Ctrl+Shift+P, type "Python: Select Interpreter" and choose Python 3.15.
  5. Open hello.py and 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:

Terminal
uv python install 3.15
uv run hello.py

You 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 py instead of python.
  • Typing terminal commands inside the REPL. python hello.py typed at the >>> prompt gives a SyntaxError. Leave the REPL with exit, then run the command in the normal terminal.
  • Naming your file after a module. A file called math.py or random.py in your folder hides the real module of that name and causes confusing errors. Choose names like my_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 cd command changes folder.

Key points

  • Check your installation with python --version (python3 --version on macOS and Linux).
  • On Windows, the Python install manager gives you the py command: py install 3.15, py list.
  • On macOS use the python.org installer; on Linux use the system python3 or your package manager.
  • The REPL (>>>) runs one line at a time and shows values without print().
  • Save programs in .py files and run them with python file.py.
  • VS Code with Microsoft's Python extension is a good free editor; uv is 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
Python
print("Rohan")
print("Pune")
Terminal
python about_me.py

In 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?

2. On Windows, which command installs Python 3.15 with the Python install manager?

3. You type python hello.py at the >>> prompt and get a SyntaxError. Why?

4. What happens if you type an expression like 5 + 3 in the REPL?

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