+1 vote

I'm trying to use Cuda GPU accelerations for some heavy parts of code through the Godot Python bindings. I've installed the python bindings using the assetlib, and it seems to work. I am now struggling with importing python modules. Note that I'm using anaconda3 for my python packages.

The question on how to import python modules have been discussed here:
https://godotengine.org/qa/37679/possible-u%20se-python-modules-and-libraries-with-godot-yes-how?show=37724#c37724

https://github.com/touilleMan/godot-python/issues/115

But so far they have not assisted me. The concrete example of how to import is to copy python folders into addons/pythonscript/x11-64/lib in the Godot project folder. This does not appear to work however.

So (as the title reads) does anyone have any ideas on how to import python modules in Godot Python?

in Engine by (140 points)

1 Answer

+1 vote
Best answer

To be able to import python libraries, it seems to work to add a path to where the python libraries are on disk in the Project Settings> General> Filesystem> Python Script> Path using the Godot editor.

I'm using conda, and I've added

/home/[username]/anaconda3/lib/python38.zip
/home/[username]/anaconda3/lib/python3.8;
/home/[username]/anaconda3/lib/python3.8/lib-dynload;
/home/[username]/anaconda3/lib/python3.8/site-packages;

which seems to make packages such as math, numpy, etc importable in Godot. The file references are on Ubuntu linux.

To find where your python libraries are, open a python shell and do:

import sys
print(sys.path)

which should give you the paths that your python installation uses to locate python libraries for import.

You can also import your own python modules by adding them to the project folder. Just make sure that res:// or any other local Godot file reference exists in the Project Settings> General> Filesystem> Python Script> Path in the Godot Editor.

by (140 points)
edited by

Note: this method makes the project unable to export later... so a better method is probably preferred.

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 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 webmaster@godotengine.org with your username.