Use uv. It will automatically install dependencies and also python versions for you. See https://docs.astral.sh/uv/guides/scripts/#using-a-shebang-to-create-an-executable-file .