I'm trying to run an external python script from Godot using the OS.execute command but it's kind of buggy and runs different python versions than on my terminal (zsh).

My code in Godot:

var output = []
exit_code = OS.execute("python", ["fetch.py"], true, output)
print(">exit_code: " + str(exit_code))

That code didn't work and after some debugging I found that it didn't recognise f-strings, a feature added in Python3.6, which lead me to believe that it runs Python2.7 or anything lower than 3.6, so I tried python3 instead of python but this didn't even run the fetch.py and just returned exit_code 1. Moreover, if I type python --version or python3 --version in the terminal, it returns Python 3.9.0. If I try the same thing in Godot, python --version returns nothing, and python3 --version returns Python 3.8.2.

This has me really confused and I've been struggling with this for a while. I've tried creating aliases in .zshrc, .bash_profile thinking maybe OS.execute() runs from bash, but no success. Does anyone know how I can fix this or where exactly Godot's OS.execute() gets its commands from/what it actually runs low level? I use MacOS v11.1 Big Sur.

I don't know what environmental settings, such as PATH, are used by OS.execute().

You might do the following from a terminal to see which versions of python are installed: $ whereis python $ whereis python3

And try using the full path for the python executable in OS.execute().

a month later

Still didn't work> @DaveTheCoder said:

I don't know what environmental settings, such as PATH, are used by OS.execute().

You might do the following from a terminal to see which versions of python are installed: $ whereis python $ whereis python3

And try using the full path for the python executable in OS.execute().

it's not working for me for some reason:

@Ywoogi said: I'm trying to run an external python script from Godot using the OS.execute command but it's kind of buggy and runs different python versions than on my terminal (zsh).

My code in Godot:

var output = []
exit_code = OS.execute("python", ["fetch.py"], true, output)
print(">exit_code: " + str(exit_code))

That code didn't work and after some debugging I found that it didn't recognise f-strings, a feature added in Python3.6, which lead me to believe that it runs Python2.7 or anything lower than 3.6, so I tried python3 instead of python but this didn't even run the fetch.py and just returned exit_code 1. Moreover, if I type python --version or python3 --version in the terminal, it returns Python 3.9.0. If I try the same thing in Godot, python --version returns nothing, and python3 --version returns Python 3.8.2.

This has me really confused and I've been struggling with this for a while. I've tried creating aliases in .zshrc, .bash_profile thinking maybe OS.execute() runs from bash, but no success. Does anyone know how I can fix this or where exactly Godot's OS.execute() gets its commands from/what it actually runs low level? I use MacOS v11.1 Big Sur.

did you get it to work?

Hi, @PHOBOSS Your post was stuck in the moderation queue. Please confirm your account with the email we sent when you signed up. Thanks.

OK, I'm back and I found 'A' solution (it's not the best but hey it's lazy and works like a charm). I used the OS.execute() to run a shell script to run my python code. I can even interact with conda and switch environments to run my object detection AI XD.

2 years later