Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

How to import 3rd packages in the main python file #94

Open
camelhehe opened this issue Aug 30, 2019 · 2 comments
Open

How to import 3rd packages in the main python file #94

camelhehe opened this issue Aug 30, 2019 · 2 comments

Comments

@camelhehe
Copy link

I just found there is no any 3rd packages were imported in your test examples.
I tried to import 3rd package, import numpy in a py file, then go run main.go, will report a failed import.
Please tell me how to import other 3rd packages installed in anaconda2/lib/python2.7/site-packages/

thanks

@camelhehe
Copy link
Author

test.py
import numpy
import sklearn

def a():
return

main.go
t := python.PyImport_ImportModule("test")

t actually is nil

Just remove import numpy and sklearn from test.py, then it works.

@sbinet
Copy link
Owner

sbinet commented Sep 2, 2019

you're probably mixing python libraries (i.e.: trying to import numpy from anaconda while you compiled go-python against another python2 interpreter.)

try this program to display the error:

package main

import (
	"log"

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

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

func main() {
	m := python.PyImport_ImportModule("numpy")
	if m == nil {
		python.PyErr_Print()
		log.Fatalf("could not import numpy")
	}
	m.DecRef()
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants