Skip to content

Commit

Permalink
PythonKit: Better support for sys.executable in macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
pvieito committed Apr 10, 2024
1 parent 41dd1e7 commit 7fcd3c2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions PythonKit/Python.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,15 @@ public struct PythonInterface {
import sys
import os
# Some Python modules expect to have at least one argument in `sys.argv`.
# Some Python modules expect to have at least one argument in `sys.argv`:
sys.argv = [""]
# Some Python modules require `sys.executable` to return the path
# to the Python interpreter executable. In Darwin, Python 3 returns the
# main process executable path instead.
# main process executable path instead:
if sys.version_info.major == 3 and sys.platform == "darwin":
sys.executable = os.path.join(sys.exec_prefix, "bin", "python3")
executable_name = "python{}.{}".format(sys.version_info.major, sys.version_info.minor)
sys.executable = os.path.join(sys.exec_prefix, "bin", executable_name)
""")
}

Expand Down

0 comments on commit 7fcd3c2

Please sign in to comment.