The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

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.

Godot version 3.3.2
in Engine by (204 points)

1 Answer

+1 vote
Best answer

Prerequisite


Python installed on the local system
test.py

Answer

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)
print(pystdout)

Need-to-know

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

Reference

OS.Execute()

by (6,942 points)
selected by

Thanks for the answer!

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.