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.

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法