Error importing packages need C: could not import C (no metadata for C)
leondgarse opened this issue · 5 comments
What are you trying to do?
- I'm trying to import
"github.com/tensorflow/tensorflow/tensorflow/go"
and"gonum.org/v1/netlib/blas/netlib"
injupyter-notebook
gophernotes kernel
, but throws errorcould not import C (no metadata for C)
. It seems like importing packages needC
is not right. - Importing those packages is all right if I
go run
it from a script.
What did you do?
- Try
import "gonum.org/v1/netlib/blas/netlib"
Github gonum/gonum:
# 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)
- Tensorflow is another case throwing
no metadata for C
error, installing needs some steps..
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)
Another jupyter Go kernel lgo can import tensorflow
succefully:
What version of Go and Gophernotes are you using?
$ go version
go version go1.13.5 linux/amd64
gophernotes$ git rev-parse HEAD
6124cc7fbaa772aedae66ac41adb2d9de2fbc60b
This is caused by the same issue reported in gomacro cosmos72/gomacro#77
I will investigate it ASAP
Understood, thanks for your explain. Glad you are looking into this. :)
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.
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.
Yes, it do works!
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. :)