sbinet / go-python

naive go bindings to the CPython2 C-API
Other
1.52k stars 138 forks source link

Error during module imports #83

Closed leobragaz closed 5 years ago

leobragaz commented 5 years ago

Hi, i'm trying to import a very simple module just to get familiar with your package but i wasn't able to do that.

This is my python file, which is placed in the same project folder of the go files.

# foo.py
def hello():
    """
    Print hello world for fun and profit.
    """
    print "hello, world!"

Main file following:

 func main(){
    py.Initialize()
    defer py.Finalize()

    fooModule := py.PyImport_ImportModule("foo")

    if fooModule == nil {
        panic("Error importing module")
    }

    helloFunc := fooModule.GetAttrString("hello")
    if helloFunc == nil {
        panic("Error importing function")
    }

    helloFunc.Call(py.PyTuple_New(0), py.PyDict_New())
}

When i build it i'll get an error cause the fooModule is actual NIL, and i don't know why, i can't find any similar problems online. Thanks in advance for help!

sbinet commented 5 years ago

it's probably an issue with your $PYTHONPATH. what is its value? and where is your foo.py file?

leobragaz commented 5 years ago

Yes it was the $PYTHONPATH not set correctly. Now it works!