How can you run Python without installing anything?
You can run Python in a web browser, on a website that loads Python into the page for you, so there's nothing to download or set up. This site works that way, and the examples and projects here have an editor with a Run button that runs your code in the browser tab you're reading this in.
How Python can run in a browser
Python is itself a program. Usually you install it on your computer, and it reads your .py file and carries out the lines one at a time. Browsers can also run programs built in a format called WebAssembly, and Pyodide is a version of Python built that way. When a page uses it, Python is downloaded into the page along with everything else, and your code runs on your own device inside the tab.
It's real Python, with the same language and the same error messages, so what you learn in the browser carries straight over when you do install Python on a computer.
Try it
This program shows which version of Python is running and does a few sums.
Run it
main.pyimport platform
import sys
print("Python", platform.python_version(), "is running on", sys.platform)
print("Seconds in a week:", 60 * 60 * 24 * 7)
print("2 to the power 100 is", 2 ** 100)
print("17 split between 4 people is", 17 / 4)Output
Press Run and what your program prints shows up here.
The first line says which version it is (3.14 at the time of writing) and that it's running on emscripten, which is the name of the toolkit used to build Python for web pages. The rest is ordinary arithmetic. 2 ** 100 comes out as 1267650600228229401496703205376, every digit of it, because Python's whole numbers can be as big as you like.
Change the numbers and run it again, or add a print line of your own with some text in quotes.
What a browser can't do
A browser keeps each page boxed in, which is good for safety but puts some things out of reach. Python in the page can't see the files on your computer, so it can't open a photo from your Documents folder. Some big libraries aren't available at all. PyTorch, which a few later projects use for machine learning, is one of them, and here import torch stops with this.
ModuleNotFoundError: No module named 'torch'
Games that open a window of their own, built with Pygame, want a real computer too. So in this course a few later projects, the PyTorch and Pygame ones, are built on your own computer, and you paste the test results back in.
When you're ready to set Python up properly, the Python at Home side project at the end of Act 1 walks you through it, from the terminal and an editor to a virtual environment and pytest. There's no hurry, though, because you can get a long way without it.
A small exercise
Add a line to the program above that works out how many minutes there are in a year of 365 days, and prints it with a label.
Show an answer
print("Minutes in a year:", 60 * 24 * 365)
That prints Minutes in a year: 525600. It's 60 minutes in an hour, times 24 hours in a day, times 365 days.
Your first program in this course is a sign for the front door, in the Course Sign project, and it runs right here in the browser like the example above. The Handbook page on print covers the one function it needs.
The project that goes with it
Course Sign is a free project in Act 1, for Paul. It runs in your browser with nothing to install, and you don't need an account for it.