Execute an external python script?

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

I would like to run a simple external Python file that prints “Hello World”, just as a test. I’ve tried researching running an external Python file, but I haven’t exactly found a straight answer yet. Any help would be appreciated.

:bust_in_silhouette: Reply From: Wakatta


Python installed on the local system


Use Godot’s OS.execute()function which is similar in operation to Python’s Subprocess

var pystdout
OS.execute("python", ["path_to_test.py"], true, pystdout)


Avoid calling this function on the main thread as inorder to get output, execution is blocked until python is finished



Thanks for the answer!

TheJokingJack | 2021-08-08 13:09

Not a problem.

Imagine having over the years amassed a huge library of libraries and operations in Python that isn’t simply transferable to GDscript or would take too much time to.

With the above in mind know that OS.execute() can also be ran in the Godot editor through plugins and tool scripts effectively operating full python programs in the process

Wakatta | 2021-08-08 14:04