Key facts
- Plain text, UTF-8 by default since Python 3; indentation is part of the syntax.
- MIME type is usually text/x-python (also seen as text/x-script.python).
- Python compiles imported modules to .pyc bytecode in a __pycache__ folder; the .py file stays the source of truth.
- Usually a few KB; projects list their third-party dependencies in requirements.txt or pyproject.toml.
- Can start with a shebang line such as #!/usr/bin/env python3 so it can run directly on Unix-like systems.
How to open a .py file
Edit in VS Code (with the Python extension), PyCharm or IDLE. Install Python from python.org or the Microsoft Store and run py script.py in Command Prompt or PowerShell.
Edit in VS Code, PyCharm or BBEdit. Install Python from python.org or with brew install python, then run python3 script.py in Terminal.
Most distributions ship Python 3. Edit with nano, vim or VS Code and run python3 script.py; add chmod +x script.py to run it as ./script.py when it has a shebang.
Common problems and fixes
- IndentationError or TabError
- The file mixes tabs and spaces or has inconsistent indentation. Configure your editor to insert 4 spaces and convert existing tabs to spaces.
- ModuleNotFoundError: No module named ...
- The package is not installed for the interpreter you are using. Create a virtual environment (python3 -m venv .venv), activate it and run pip install -r requirements.txt.
- SyntaxError: Non-UTF-8 code or UnicodeDecodeError
- The file was saved in a legacy encoding such as Windows-1252. Re-save it as UTF-8, or read data files with an explicit encoding= argument.
- Double-clicking the file flashes a window and closes
- The script finished or crashed immediately. Run it from a terminal so you can read the output and any traceback.
- 'python' is not recognized / command not found
- Python is not on your PATH. On Windows use the py launcher or re-run the installer with Add python.exe to PATH; on macOS and Linux call python3.
Often converted to or from: Jupyter notebook (.ipynb), Standalone executable (PyInstaller), PHP or Node.js (manual port), Plain text