Python 3D Academyবাংলা

Python on your own computer

🌍 In real life. You learn to ride a bicycle in a quiet park, then one day you ride it on the road to go somewhere. This course is the quiet park: Python runs in your browser and nothing can go wrong. When you want to build your own projects, work with files on your computer or use the thousands of free Python libraries, you install Python on your computer.

You don't need it to carry on with this course: every lesson still runs here. Do it now if you're curious, or come back to this lesson later.

The idea in one sentence: install Python once, write your code in a file whose name ends in .py, and run it from a terminal with python hello.py.

Its words:

  • interpreter: the Python program itself, which reads your code and runs it (what runs behind ▶ Run here)
  • terminal: a window where you type commands for the computer (Terminal or Command Prompt on Windows, Terminal on Mac and Linux)
  • editor: the app you write code in; VS Code is free and popular
  • .py file: a plain text file holding Python code, like hello.py
  • PATH: the list of folders your computer searches when you type a command like python

Step by step: install Python.

On Windows

  1. Open python.org/downloads and click the big Download Python 3 button.
  2. Run the file you downloaded. On its first screen, tick "Add python.exe to PATH": this is the most important step. Then click Install Now. (If python.org gives you the Python install manager instead, run it and accept what it suggests: it sets this up for you.)
  3. Open Terminal (search for it in the Start menu), type python --version and press Enter. You should see something like Python 3.14.0. If that doesn't work, try py --version.

On a Mac

  1. From python.org/downloads, download the macOS installer and open it. Click through its steps.
  2. Open Terminal (press ⌘ Space and type Terminal) and type python3 --version. On a Mac the command is python3, not python.

On Linux Python is usually there already: type python3 --version in a terminal. If it's missing on Ubuntu or Debian, sudo apt install python3 installs it.

On a phone or tablet you can't install the usual Python. Keep learning here; on Android, apps such as Pydroid 3 can also run Python files.

How Python does it: your first program on your computer.

  1. Install VS Code from code.visualstudio.com. Open it, click the Extensions icon on the left, search for Python and install the one by Microsoft.
  2. Make a folder for your practice, say python-practice on your Desktop. In VS Code, choose File → Open Folder and pick it.
  3. Make a new file called hello.py, type the program below and save it (Ctrl+S, or ⌘S on a Mac).
  4. Click the ▶ button at the top right (Run Python File). The output appears in the terminal at the bottom of VS Code.

You can also run it yourself: in that terminal type python hello.py (on a Mac or Linux, python3 hello.py) and press Enter. Python reads the file from top to bottom, exactly as here.

print("Hello from my computer!")
print("Python is installed.")
This is hello.py. The same code runs here and on your computer, with the same output.

Two ways to talk to Python. A file is for programs you keep. For a quick try, type just python (on a Mac, python3) in the terminal: you get Python's own prompt, >>>. Type a line, press Enter, and the answer appears straight away, like >>> 2 + 3 showing 5. Type exit() to leave it.

This is the line Python would print for 2 + 3 in a program:

print(2 + 3)
In a file you need print() to see a result; at the >>> prompt, Python shows it for you.

Mistakes and edge cases.

  • 'python' is not recognized as an internal or external command, operable program or batch file. (Windows) The Add python.exe to PATH box wasn't ticked. Run the installer again, choose Modify, and tick Add Python to environment variables, or type py instead of python. Close the terminal and open a new one after installing.
  • Typing python opens the Microsoft Store. That's a Windows shortcut, not Python. Install from python.org, or turn the shortcut off in Settings → Apps → Advanced app settings → App execution aliases.
  • zsh: command not found: python (Mac) Use python3.
  • python: can't open file '…hello.py': [Errno 2] No such file or directory The terminal is looking in a different folder. Go to your file's folder with cd, like cd Desktop/python-practice, or open the folder in VS Code and use its terminal.
  • Commands and code in the wrong place. python hello.py is a terminal command: written inside hello.py it gives SyntaxError: invalid syntax. And Python code typed into the terminal (not after >>>) only gets an error from the terminal. Commands go in the terminal; Python code goes in the file, or after >>>.
  • Don't name your file after a Python module, like random.py or turtle.py. Later, import random would load your file instead of Python's.