简体   繁体   English

在项目中使用go模块时如何导入tensorflow go包?

[英]How to import the tensorflow go packages when using go modules in a project?

So I have a project and I am using go modules. 所以我有一个项目,正在使用go模块。 However I need to use the tensorflow package, but it seems tensorflow is not yet supporting go modules. 但是我需要使用tensorflow包,但似乎tensorflow尚不支持go模块。 Is there a way to import those two dependencies despite the lack of module definitions? 尽管缺少模块定义,有没有办法导入这两个依赖关系?

The following 2 imports seem to cause the problems: 以下2种导入似乎会引起问题:

tf "github.com/tensorflow/tensorflow/tensorflow/go"
"github.com/tensorflow/tensorflow/tensorflow/go/op"  

When I try to download the packages I get the following output: 当我尝试下载软件包时,得到以下输出:

$ go get -u "github.com/tensorflow/tensorflow/tensorflow/go/op"
go: finding github.com/tensorflow/tensorflow/tensorflow/go/op latest
go: finding github.com/tensorflow/tensorflow/tensorflow/go latest
go: finding github.com/tensorflow/tensorflow/tensorflow latest
go get github.com/tensorflow/tensorflow/tensorflow/go/op: no matching versions for query "latest"

However in my test project which still used the old way of importing packages everything worked just fine. 但是,在我的测试项目中,它仍然使用导入包的旧方法,一切正常。

Edit: 编辑:

After some testing I realized that the issue only happens with the go packages of tensorflow. 经过一些测试,我意识到该问题仅在tensorflow的go软件包中发生。 All others, even if not originally written with go modules, work just fine. 所有其他代码,即使不是最初使用go模块编写的,也可以正常工作。

I corrected the imports in the original question, as well as the title. 我更正了原始问题中的导入内容以及标题。

So for now I use a dirty workaround to get around this issue. 因此,现在我使用一种肮脏的解决方法来解决此问题。 I just ripped out go modules from my project entirely by removing go.mod and go.sum files and setting GO111MODULE=off . 我只是通过删除go.modgo.sum文件并设置GO111MODULE=off从项目中完全删除了go模块。

It is not the best solution, hence I do not accept the answer, but for now I can continue working. 这不是最佳解决方案,因此我不接受答案,但是现在我可以继续工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM