I am trying to use a python function inside of my GDscript and I get this error: Invalid call. Nonexistent function 'do_numpy' in base 'Node'.

here is my GDscript:

extends Node2D

onready var numpy = get_node("/root/world/Node")

func _ready():
    
    var world = numpy.do_numpy()

Python:

from godot import exposed, export
from godot import *
import numpy as np


@exposed
class numpy(Node):

    def _ready(self):
        """
        Called every time the node is added to the scene.
        Initialization here.
        """
        pass

    def do_numpy(self):
        print("test")

I haven’t used Python in Godot, but if it’s like calling C# code from GDScript, then you’ll need to use the call function:

numpy.call(“do_numpy”)

Thanks for the reply but unfortunately that did not work either:

Invalid call. Nonexistent function 'do_numpy (via call)' in base 'Node'.

6 days later

Hey thanks for still checking up on this, I just figured out the issue. It had to do with me trying to load the numpy library. I had originally thought that I could just install it globally and it would find it, but I was wrong and a friend pointed out that the PythonScript addon is installs a version of python locally on the project and independent from the rest of python. So I followed the directions here: https://godotengine.org/asset-library/asset/179 (I am using Linux btw) and installed the numpy library from the local pip in the project.

And for those that may have an issue trying to use pip, at least on Linux, make the python3 executable (chmod +x python3) and then run python -m pip install thing. And as the guide states if pip is not found run python -m ensurepip.

Thanks again TwistedTwigleg, I had seen that first issue you linked but taking another look at it made me realize that he was not using a library and then found the true issue. Another thing that didn't help me resolve this issue is either with Godot showing the improper error or the PythonScript addon just has the file not load if it fails at loading the library. I will file a ticket to see if there can potentially be a better output on Godot to state that the python script had an issue loading a library.

Awesome, I’m glad you were able to figure it out! :)

10 months later