Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing packages need C: could not import C (no metadata for C) #194

Open
leondgarse opened this issue Jan 8, 2020 · 5 comments
Assignees

Comments

@leondgarse
Copy link

What are you trying to do?

  • I'm trying to import "github.com/tensorflow/tensorflow/tensorflow/go" and "gonum.org/v1/netlib/blas/netlib" in jupyter-notebook gophernotes kernel, but throws error could not import C (no metadata for C). It seems like importing packages need C is not right.
  • Importing those packages is all right if I go run it from a script.

What did you do?

# Install gonum + netlib
go get -u -t gonum.org/v1/gonum/...
go get -d gonum.org/v1/netlib/...

# Install OpenBLAS
git clone https://github.com/xianyi/OpenBLAS
cd OpenBLAS
make
make install # This will install OpenBLAS lib to /opt/OpenBLAS/lib
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib/:$LD_LIBRARY_PATH
CGO_LDFLAGS="-L/opt/OpenBLAS/lib -lopenblas" go install gonum.org/v1/netlib/blas/netlib

Open a jupyter-notebook --> New --> Go, run:

import (
    "fmt"
    "gonum.org/v1/gonum/mat"
    "gonum.org/v1/gonum/blas/blas64"
    "gonum.org/v1/netlib/blas/netlib"
)

// error loading package "gonum.org/v1/netlib/blas/netlib" metadata: /home/leondgarse/go/pkg/mod/gonum.org/v1/netlib@v0.0.0-20191229114700-bbb4dff026f8/blas/netlib/blas.go:13:8: could not import C (no metadata for C)

Then open a jupyter-notebook --> New --> Go, run again:

import (
    "fmt"
    tf "github.com/tensorflow/tensorflow/tensorflow/go"
)
// error loading package "github.com/tensorflow/tensorflow/tensorflow/go" metadata: /home/leondgarse/go/pkg/mod/github.com/tensorflow/tensorflow@v2.0.0+incompatible/tensorflow/go/attrs.go:21:8: could not import C (no metadata for C)

What did you expect to happen?

Expect importing successfully with no error throws out.

What actually happened?

Importing throws error could not import C (no metadata for C)
Selection_147

Another jupyter Go kernel lgo can import tensorflow succefully:
Selection_148

What version of Go and Gophernotes are you using?

$ go version
go version go1.13.5 linux/amd64
gophernotes$ git rev-parse HEAD
6124cc7fbaa772aedae66ac41adb2d9de2fbc60b
@cosmos72
Copy link
Member

cosmos72 commented Jan 8, 2020

This is caused by the same issue reported in gomacro cosmos72/gomacro#77
I will investigate it ASAP

@leondgarse
Copy link
Author

Understood, thanks for your explain. Glad you are looking into this. :)

@cosmos72
Copy link
Member

cosmos72 commented Jan 9, 2020

Can you execute the shell commands

GO111MODULE=on go get -v github.com/tensorflow/tensorflow/tensorflow/go
GO111MODULE=on go install -v github.com/tensorflow/tensorflow/tensorflow/go

and then try again to import "github.com/tensorflow/tensorflow/tensorflow/go" ?

I am trying to understand if such workaround could work - if it does, I can modify gophernotes to run it automatically.

@cosmos72
Copy link
Member

cosmos72 commented Jan 9, 2020

I tried them myself: no luck.

Thus I just added a workaround: the special command %go111module {on|off} enables/disables GO111MODULE support when importing packages.

By default it is on, but to import packages that expose C types/symbols - such as github.com/tensorflow/tensorflow/tensorflow/go and gonum.org/v1/netlib/blas/netlib, you should turn it off.

Let me know if it helps.

@cosmos72 cosmos72 self-assigned this Jan 9, 2020
@leondgarse
Copy link
Author

leondgarse commented Jan 10, 2020

Yes, it do works!
Selection_149
But import "gonum.org/v1/netlib/blas/netlib" throws another error error executing "/usr/local/go/bin/go build -buildmode=plugin" in directory. It also works well in a script with go run.

// test_netlib.go
package main
import (
    "fmt"
    "gonum.org/v1/gonum/mat"
    "gonum.org/v1/gonum/blas/blas64"
    blas_netlib "gonum.org/v1/netlib/blas/netlib"
)

func main() {
    blas64.Use(blas_netlib.Implementation{})
    zero := mat.NewDense(2, 2, nil)
    fmt.Println(zero)
}

Run

$ CGO_LDFLAGS="-L/opt/OpenBLAS/lib -lopenblas" go run test_netlib.go
&{{2 2 [0 0 0 0] 2} 2 2}

Also tried these two commands

$ GO111MODULE=off CGO_LDFLAGS="-L/opt/OpenBLAS/lib -lopenblas" go run test_netlib.go
&{{2 2 [0 0 0 0] 2} 2 2}

$ GO111MODULE=on CGO_LDFLAGS="-L/opt/OpenBLAS/lib -lopenblas" go run test_netlib.go
go: finding gonum.org/v1/netlib latest
&{{2 2 [0 0 0 0] 2} 2 2}

I think it's another issue though. I'm still trying to solve this.

Thanks for your work. I'm glad tensorflow works. :)

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

No branches or pull requests

2 participants