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

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

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.