I am trying to import a package in my golang code. But it is showing me this error:
cannot find package "github.com/mattbaird/jsonpatch" in any of:
/opt/go/src/github.com/mattbaird/jsonpatch (from $GOROOT)
/chaincode/input/src/github.com/mattbaird/jsonpatch (from $GOPATH)
/opt/gopath/src/github.com/mattbaird/jsonpatch "
Can somebody help me fix this?
Thanks.
Recheck your environment variables($GOPATH, $GOROOT).
The problem you are facing is that, your code is searching for the package github.com/mattbaird/jsonpatch in /opt/go/src/github.com/, /chaincode/input/src/github.com/ and /opt/gopath/src/github.com/ directories. But you have installed the package in C:\Users\xyz\go\src\github.com directory.
Ensure your $GOPATH environment variable is set up correctly.
Then double check the packages are installed, if not you need to install the package which you can do with.
go get github.com/mattbaird/jsonpatch
Related
I was migrating my Golang programs from windows to Centos 7
It worked perfectly in Windows
but when I tried to compile on centos I get errors like
main.go:20:3: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
/root/work/src/github.com/BurntSushi/toml (from $GOPATH)
main.go:15:3: cannot find package "github.com/dgrijalva/jwt-go" in any of:
/usr/local/go/src/github.com/dgrijalva/jwt-go (from $GOROOT)
/root/work/src/github.com/dgrijalva/jwt-go (from $GOPATH)
main.go:16:3: cannot find package "github.com/gwlkm_service/config" in any of:
/usr/local/go/src/github.com/gwlkm_service/config (from $GOROOT)
/root/work/src/github.com/gwlkm_service/config (from $GOPATH)
kinda new to centos so idk what to do
looks like you have configured your GOPATH, without Go Module, you can use go get [package path] to download imported packages.
go get github.com/BurntSushi/toml
go get github.com/dgrijalva/jwt-go
go get github.com/gwlkm_service/config
Precisely
your go installation on server seems in /usr/local/go and
your project is in /root/work
so all your dependencies should be either in /root/work/src or /usr/local/go/src
now coming to action check your GOPATH with running echo $GOPATH
assuming it is automatically set to /usr/local/go/src
If not then follow - How do I SET the GOPATH environment variable on Ubuntu? What file must I edit?
If everything is ok then in your folder run go mod init
this will create mod file which will help you in further installations
look into - https://blog.golang.org/using-go-modules
then run go get commands as above #beiping96 said
go get github.com/BurntSushi/toml
go get github.com/dgrijalva/jwt-go
go get github.com/gwlkm_service/config
NOTE - after completing above process you will generate go modules file(same as package.json) and in future you won't need to care about dependencies
While setting up my new Go with Sublime I wanted to install Oracle tools with the following command
go get golang.org/x/tools/cmd/oracle
package golang.org/x/tools/cmd/oracle: cannot find package "golang.org/x/tools/cmd/oracle" in any of:
C:\Go\src\golang.org\x\tools\cmd\oracle (from $GOROOT)
C:\Users\User\Go\src\golang.org\x\tools\cmd\oracle (from $GOPATH)
What am I doing wrong here?
If you check the package link you'll see it throws NOT FOUND (package link here)
Based on this, it seems that the package was renamed to guru, this is the correct installation:
go get golang.org/x/tools/cmd/guru
The command that works for me is:
go get golang.org/x/tools/cmd/guru
(the same as before, just with the new name of the tool - guru, instead of oracle)
if %GOBIN% // $GOBIN is in your path, This command will be magic:
go get golang.org/x/tools/...
I'm in my go root path and I get error the following errors when I perform the go install command...
main.go:4:2: cannot find package "fmt" in any of:
/usr/lib/go-1.6/bin/src/fmt (from $GOROOT)
/home/rbtlong/go/src/fmt (from $GOPATH)
main.go:6:2: cannot find package "io/ioutil" in any of:
/usr/lib/go-1.6/bin/src/io/ioutil (from $GOROOT)
/home/rbtlong/go/src/io/ioutil (from $GOPATH)
main.go:5:2: cannot find package "net/http" in any of:
/usr/lib/go-1.6/bin/src/net/http (from $GOROOT)
/home/rbtlong/go/src/net/http (from $GOPATH)
package rbtlong.com
imports runtime: cannot find package "runtime" in any of:
/usr/lib/go-1.6/bin/src/runtime (from $GOROOT)
/home/rbtlong/go/src/runtime (from $GOPATH)
I have tried unsetting the GOROOT, but it doesn't seem to work.
Per discussion, it sounds like your install is a bit mucked up. Reinstalling Go seems to be the best option.
For others investigating GOROOT issues, the first step is almost always going to be to unset GOROOT. In most cases, GOROOT is not needed, and tends to muck up the works.
Another option for managing your Go installs more easily (and largely automagically), which also gives a homebrew-like version swapping capability and a containerization similar to virtualenv for Python or rvm for Ruby, is to use GVM.
apparently, the definition was defined in $HOME/.bashrc after removing the definition for GOPATH and GOROOT, then manually removing the folder at /usr/lib/go-1.6 then reinstalling it using the instructions here https://golang.org/doc/install#install then setting the PATH and GOPATH by editing $HOME/.profile:
PATH="[...]:/usr/local/go/bin[...]"
export GOPATH="$HOME/go"
it appears to be working now...
Before doing go install check for the Go version and Go path, if these are correct you won't get any error.
Please, install Go latest version from the official website and re-try once.
go:5:2: cannot find package "github.com/googollee/go-socket.io" in any of:
/usr/local/go/src/github.com/googollee/go-socket.io (from $GOROOT)
/Users/YoungHoonKim/Documents/chat/src/github.com/googollee/go-socket.io (from $GOPATH)
I'm getting this error while trying to compile my chat.go file with LiteIDE. I'm following a guide to build a chatserver, so I don't know where this package should be. any help?
Double-check your actual go work directory with echo $GOPATH in your terminal.
This will be your starting point to identify if you have this package at all, for example you should be able to see this package doing cd $GOPATH/src/github.com/googollee/go-socket.io.
For more details on correct directory location (workspace in general) please check https://golang.org/doc/code.html
This is my first time asking a question here, anyway, I am wondering why it says it can't find the package, even though github.com/JohnDoe/temperature/conversion/conv is inside the $GOPATH
[johndoe#johndoe temperature]$ go run main.go
main.go:5:2: cannot find package "github.com/JohnDoe/temperature/conversion/conv" in any of:
/usr/local/go/src/github.com/JohnDoe/temperature/conversion/conv (from $GOROOT)
/home/johndoe/Workspace/Go/src/github.com/JohnDoe/temperature/conversion/conv (from $GOPATH)
more details:
[johndoe#johndoe conversion]$ pwd
/home/johndoe/Workspace/Go/src/github.com/JohnDoe/temperature/conversion
[johndoe#johndoe conversion]$ ls
conv.go
Thoughts?
You're mistaking packages and file. In go (contrary to say… python), a package is represented by a directory, and files in this directory are nothing more than code. So you should import the github.com/JohnDoe/temperature/conversion package.