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

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

Description

@camelhehe

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

Activity

  1. camelhehe commented on Aug 30, 2019

    @camelhehe
    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.

  2. sbinet commented on Sep 2, 2019

    @sbinet
    Owner

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions