Skip to content

GOPATH environment variable is ignored when using interpreter #1517

Open
@karelorigin

Description

@karelorigin

The following program sample.go triggers an unexpected result

package main

import (
	"fmt"

	"github.com/traefik/yaegi/interp"
)

var script = `package main

import (
	"fmt"
)

func main() {
	fmt.Println("hello there")
}
`

func main() {
	i := interp.New(interp.Options{})

	_, err := i.Eval(script)
	if err != nil {
		fmt.Println("Error:", err)
	}
}

Expected result

$ env GOPATH=~/go/ go run main.go
// hello there

Got

$ env GOPATH=~/go/ go run main.go
// Error: 4:2: import "fmt" error: unable to find source related to: "fmt". Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

Yaegi Version

v0.15.0

Additional Notes

Yaegi states that the GOPATH environment variable is used for finding packages, except it never is. This only seems to work for the Yaegi binary, which explicitly passes it to the interpreter options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/docbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions