sbinet / go-python

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

panic error by import turbodbc lib #56

Closed cooljl31 closed 5 years ago

cooljl31 commented 6 years ago

System info: MacOs Sierra 10.12.6

Error could not inport turbodbc

package main

import (
    "fmt"

    python "github.com/sbinet/go-python"
)

func init() {
    err := python.Initialize()
    if err != nil {
        panic(err.Error())
    }
}

func main() {
    turboExasol := python.PyImport_ImportModule("turbodbc")
    if turboExasol != nil {
        panic("could not inport turbodbc")
    }
    fmt.Printf("%v", turboExasol)
    connection := turboExasol.GetAttrString(`dsn=exasolution-io352fw_64`)
    if connection != nil {
        panic("could not get turbodbc(dsn=exasolution-io352fw_64)")
    }
    fmt.Printf(" %v", connection)
}
cooljl31 commented 6 years ago

I forgot to mention the library correctly install

Requirement already satisfied: turbodbc in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: pybind11>=2.1.0 in /usr/local/lib/python3.6/site-packages (from turbodbc)
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from turbodbc)

this python script work

from turbodbc import connect

connection = connect(dsn = 'exasolution-io352fw_64')
cursor = connection.cursor()
cursor.execute("SELECT CATEGORY_NAME FROM STATISTICS.WEB_CATEGORY WHERE statistics.web_category.customer_id = 0001")

for row in cursor:
    print(row)
sbinet commented 6 years ago

PyImport_ImportMode returns a PyObject*: https://docs.python.org/2/c-api/import.html#c.PyImport_ImportModule

so the test:

    if turboExasol != nil {
        panic("could not inport turbodbc")
    }

should really read:

    if turboExasol == nil {
        panic("could not inport turbodbc")
    }

that said, do note that sbinet/go-python only supports Python-2, and it seems turbodbc is picked up from a python3.6 install (and has thus been, presumably, compiled against Python-3).

cooljl31 commented 6 years ago

i have the same error on Python-2.7 screen shot 2017-09-14 at 9 53 14 pm

Requirement already satisfied: turbodbc in /usr/local/lib/python2.7/site-packages
Requirement already satisfied: pybind11>=2.1.0 in /usr/local/lib/python2.7/site-packages (from turbodbc)
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from turbodbc)
sbinet commented 6 years ago

ok. but... did you notice that PyImport_ImportModule returns the module so you should write:

if turboExasol == nil {
    panic("could not inport turbodbc")
}

ie: your if condition should be reversed.

sbinet commented 5 years ago

Closing of old age.