How to Open a PY File
A .py file is plain-text Python source code. Any text editor can display it, but to see what it actually does, you need to run it with a Python interpreter — including, right here, one running entirely in your browser.
Open & Run a PY File Online
Drop a .py file below to see its source with syntax highlighting and a quick structural overview (imports, functions, classes) — and actually run it using a real Python interpreter compiled to WebAssembly, right in this page.
🔒 Nothing is uploaded — your file never leaves this deviceClick "Run this script" to execute it with a real Python interpreter, right in this page.
input(), and a script that imports a third-party package like NumPy or Pandas won't find it here). Scripts get 20 seconds before this stops them automatically.
On this page
What is a PY file?
A .py file is a plain-text source file written in Python, one of the world's most widely used programming languages, created by Guido van Rossum and first released in 1991, now maintained by the Python Software Foundation. Being plain text, a .py file opens in literally any text editor — there's no special binary structure to it, the same way there isn't for a .txt file.
What makes a .py file useful is that it can be executed: a Python interpreter reads the file top to bottom and carries out the instructions it contains, whether that's printing text, doing calculations, processing data, or running a full application. That's the real reason "opening" a .py file usually means something different from opening a .pdf or a .jpg — you're not just viewing content, you're choosing whether to read it or run it.
How to run a PY file on Windows
- Download and install Python from python.org, making sure to check "Add Python to PATH" during setup — this step trips up most first-time installs.
- Open a terminal in the script's folder (Shift + right-click the folder, choose "Open PowerShell window here" or similar).
- Run:
python filename.py - The script's output appears directly in the terminal.
Double-clicking a .py file in File Explorer will also run it if Python is installed and associated with the extension, but the terminal method above lets you actually see any output or errors, which double-clicking usually doesn't.
How to run a PY file on Mac
- Open Terminal (Applications > Utilities > Terminal).
- Navigate to the script's folder:
cd path/to/folder - Run:
python3 filename.py
Modern macOS doesn't ship a full Python installation by default — if python3 isn't found, install it from python.org or via Homebrew: brew install python.
How to run a PY file on Linux
Most Linux distributions come with Python pre-installed. Open a terminal and run:
python3 filename.py
If it's not installed, get it with your package manager, e.g. sudo apt install python3 on Debian/Ubuntu, or sudo dnf install python3 on Fedora.
Which editor should I use?
For quick viewing, any text editor works. For actually writing or editing Python code, a dedicated editor makes a big difference:
- Visual Studio Code (free) — the most popular general-purpose editor, with an excellent Python extension.
- PyCharm (free Community edition available) — a full Python-specific IDE with deep debugging and refactoring tools.
- Jupyter Notebook — ideal for data science and step-by-step, cell-by-cell exploration rather than running a whole script at once.
Is it safe to run a .py file?
Only if you trust where it came from. Unlike opening a document or image, running a Python script means letting arbitrary code execute on your computer — it can read, modify or delete files, make network requests, or install other software, exactly like any other program. Read through the code first (or use the viewer above) if you're at all unsure, and never run a script downloaded from an untrusted source without understanding what it does.
Common PY file errors and how to fix them
"'python' is not recognized as an internal or external command" (Windows)
Python isn't in your system PATH. Reinstall from python.org with "Add Python to PATH" checked, or add the install folder to PATH manually.
"ModuleNotFoundError: No module named '...'"
The script imports a package that isn't installed. Install it with pip install packagename (matching the name shown in the error, which is sometimes different from the import name).
"SyntaxError" pointing at code that looks fine
Usually a Python version mismatch — the script was written for Python 2 (which uses different syntax for things like print) but you're running Python 3, or vice versa. Check which version the script expects.
"IndentationError"
Python uses indentation to define code blocks, so mixing tabs and spaces, or an inconsistent indent level, causes this. Most editors can auto-convert tabs to spaces to fix it.
Frequently asked questions
What program opens a .py file?
A .py file is plain text, so any text editor (Notepad, TextEdit, VS Code, Sublime Text, PyCharm) can open and display it. To actually run the code as a program, you need a Python interpreter installed (from python.org, or already present on most Mac and Linux systems), or you can run it directly in your browser using the online tool on this page without installing anything.
Can I run a Python file without installing Python?
Yes. The online tool on this page runs a real Python interpreter (compiled to WebAssembly) directly in your browser, so you can execute a .py script's standard-library code with no installation. For scripts that need third-party packages like NumPy or Pandas, or that need a full desktop/GUI environment, you'll still want a local Python installation.
Why do I get "python is not recognized" on Windows?
This means Python isn't in your system's PATH, usually because the "Add Python to PATH" option wasn't checked during installation. Reinstall Python from python.org and make sure that checkbox is selected, or manually add Python's install folder to your PATH environment variable.
Is it safe to run a .py file from the internet?
Only if you trust its source. A Python script can do anything a program can do — read, modify or delete files, access the network, or worse — so treat an unfamiliar .py file with the same caution as any executable. Reading the code first (or using this page's viewer) before running it is good practice whenever you're unsure.
Last updated September 21, 2026.