How to Correctly Execute a Python Script from Within a .gd Script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By scrubswithnosleeves

Hey All,

I am trying to execute a .py file from a .gd script with the following code:

var global_dir_path = ProjectSettings.globalize_path("res://OAuth2.0")

var ERR = OS.execute("python", [global_dir_path + "/"], true)
	if ERR == OK:

I am getting an ERR == 1, which is “FAILED = 1 — Generic error” from the Godot Docs.

I know for a fact that the script works when run from my IDE and the command line, and that the path to the .py script is correct. I am wondering if there are some permissions I am violating or something?

The .py script accesses scripts in its local directory. do you think that is the issue somehow?

Are you able to execute the exact same command in cmd/terminal?

timothybrentwood | 2021-08-11 22:00

Yes this works in the terminal. I think it might have something to do with the fact that I have python as an alias for python3.9 in my terminal.

scrubswithnosleeves | 2021-08-11 22:22

:bust_in_silhouette: Reply From: scrubswithnosleeves

The problem was solved by using the absolute path for the python executable for some reason. On a mac, you can find this by doing where python3 in the terminal. I did where python3.9 because I knew I wanted that version to be used.

I changed to

OS.execute("/usr/local/bin/python3.9", [global_dir_path + "/"], true)