Apple removed the Python 2.7 installation from macOS in the 12.3 release in March 2022. The path /usr/bin/python no longer exists, and a shebang of '#!/usr/bin/env python' fails with 'env: python: No such file or directory' unless something else has provided that name.
/usr/bin/python3 still exists, but it is a stub that triggers the command line tools installer on first use rather than a full interpreter, and its version tracks whatever Xcode ships rather than anything you chose. Apple documents the system Python as being for its own use and not a supported runtime for third-party software.
The correct response is to install an interpreter you control, through Homebrew's python@3.12 or a version manager, and to write shebangs as '#!/usr/bin/env python3'. In virtual environments, always create with the explicit interpreter you want rather than relying on PATH resolution. Build scripts that call 'python' by bare name should be updated to 'python3', since no version of macOS since 12.3 provides the unsuffixed name at all.