How to open .PY files on Mac
To open .PY files on Mac, view/edit: open in VS Code or PyCharm; review unknown scripts before running.
Step-by-step instructions
- View/edit: open in VS Code or PyCharm; review unknown scripts before running.
- Run: Terminal → cd to the directory → python3 ./yourfile.py. With a shebang and chmod +x, ./yourfile.py works the same way.
- Virtualenv: python3 -m venv .venv, source .venv/bin/activate, then pip install -r requirements.txt when the project provides it.
Common issues
Double-click runs the script or closes instantly
File associations may launch python.exe without a persistent console, hiding errors.
- Run from PowerShell/Terminal with py/python3 plus the script path.
- Add input("Press Enter…") only for quick debugging—prefer logging for real apps.
ModuleNotFoundError or ImportError
Dependencies are missing or you are outside the virtual environment / wrong cwd.
- Activate the documented venv, then pip install -r requirements.txt or poetry install.
- Run from the repository root or use PYTHONPATH only when you understand why it is needed.
python3: command not found / py not recognized
Python is not installed or not on PATH.
- Windows: install from python.org and tick “Add to PATH”, or use py -0 to list managed versions.
- macOS/Linux: install via official installer, Homebrew, or distro packages; confirm with python3 --version.
Wrong Python version for the project
Modern projects pin 3.10+ while the OS default may be older.
- Read .python-version, runtime.txt, or CI configs.
- Use py -3.12 script.py on Windows or a version manager on Unix (pyenv, asdf) to match the team.
Security note
Running python malware grants file, network, and process access as your user. Inspect source from strangers before execution; never curl | python a remote script blindly.