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

  1. View/edit: open in VS Code or PyCharm; review unknown scripts before running.
  2. Run: Terminal → cd to the directory → python3 ./yourfile.py. With a shebang and chmod +x, ./yourfile.py works the same way.
  3. 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.

  1. Run from PowerShell/Terminal with py/python3 plus the script path.
  2. 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.

  1. Activate the documented venv, then pip install -r requirements.txt or poetry install.
  2. 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.

  1. Windows: install from python.org and tick “Add to PATH”, or use py -0 to list managed versions.
  2. 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.

  1. Read .python-version, runtime.txt, or CI configs.
  2. 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.

Back to .PY extension page