dounaoji2054 2019-08-08 03:54
浏览 134
已采纳

转到模块:“找不到提供程序包的模块”导入依赖项的子程序包

I have a project outside of $GOPATH and I want to use go mod. However, when I copy the code of from a project in $GOPATH and run $ GO111MODULE=on go mod init github.com/jgoc/modtest $ GO111MODULE=on go run main.go, I get an error

go version go1.12.5 windows/amd64

package main

import (
    "github.com/hajimehoshi/ebiten"
    "github.com/hajimehoshi/ebiten/vector"
)

build command-line-arguments: cannot load github.com/hajimehoshi/ebiten/vector: cannot find module providing package github.com/hajimehoshi/ebiten/vector

Example: https://github.com/jgoc/modtest

  • 写回答

1条回答 默认 最新

  • douhaodang0403 2019-08-08 23:43
    关注

    Based on the recent edits to supply actual package names, it sounds like you need to use a version of your github.com/hajimehoshi/ebiten dependency that has a vector package.

    The latest version of github.com/hajimehoshi/ebiten with a valid semver release tag is https://github.com/hajimehoshi/ebiten/tree/v1.9.3. That version does not appear to have a vector package.

    The @master version does have a vector package. @v1.10.0-alpha does not have a vector package. Maybe start with @master and at least see if you can compile?

    This worked for me:

    go get -d github.com/hajimehoshi/ebiten/vector@master

    For more details, please read the How to Upgrade and Downgrade Dependencies section of the modules wiki.


    Also, what is the actual name of your module? And what are the actual import paths you are using to import the code that lives in that module?

    You wrote:

    go mod init Desktop/modtest

    Normally, the name of a module (also known as the "module path") should start with a hostname like github.com, and most often a repo, such as:

    go mod init github.com/my/repo.

    You then import packages in your .go code using import paths that start with that full module path that you passed to go mod init, such as:

    import "github.com/my/repo/pkg1".

    Using your example, it would be:

    go mod init github.com/<author>/<package>

    And the imports would be:

    import (
        "github.com/<author>/<package>"
        "github.com/<author>/<package>/<sub-package>"
    )
    

    If your module path does not agree with your import paths, you can get errors similar to what you are seeing. (Your "module path" is what you pass as the argument to go mod init, and then you can see it on the module line in your go.mod file).

    Please see this answer for some more context and a few more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度