pgx icon indicating copy to clipboard operation
pgx copied to clipboard

How to install that package?

Open phtdacosta opened this issue 6 years ago • 11 comments

I used the command go get github.com/jackc/pgx/v4 and got the error package github.com/jackc/pgx/v4: cannot find package "github.com/jackc/pgx/v4" in any of: c:\go\src\github.com\jackc\pgx\v4 (from $GOROOT) C:\Users\pedro\go\src\github.com\jackc\pgx\v4 (from $GOPATH)

I am new to golang, but I did actually made some other packages to work, so I am tremendously confused since PGX gives no clue on how to install it.

phtdacosta avatar May 11 '20 07:05 phtdacosta

@phtdacosta

It fails because you are not running the command inside a Go-Project that uses go-modules. Run it from the directory where your go.mod file is (or a subdir). You can create a go mod file via go mod init.

See also: https://github.com/jackc/pgx/issues/613 https://github.com/jackc/pgx/issues/603 https://github.com/golang/go/wiki/Modules

fho avatar May 11 '20 16:05 fho

@fho I am seeing the same issue but I had been using this module without error on a project which has been building fine with the dependency. Something has changed between last Friday and today.

package github.com/jackc/pgx/v4: cannot find package "github.com/jackc/pgx/v4" in any of: /usr/lib/go-1.10/src/github.com/jackc/pgx/v4 (from $GOROOT) /home/steve/code/myproject/src/github.com/jackc/pgx/v4 (from $GOPATH) /home/steve/go/src/github.com/jackc/pgx/v4

steowens avatar May 11 '20 17:05 steowens

@steowens

cannot find package "github.com/jackc/pgx/v4" in any of: /usr/lib/go-1.10/src/github.com/jackc/pgx/v4 (from $GOROOT)

That looks like you are using Go 1.10. Go modules are only supported since version 1.11.

fho avatar May 11 '20 18:05 fho

Yep that is exactly what changed, I was able to resolve the dependency once upgrading to version 1.14. Thanks

steowens avatar May 11 '20 18:05 steowens

Thank you so much for your patience, @fho. By the way, I am still a bit confused about those modules thing even after reading the references you gave. I tried do what you said, ran the command and got the following output PS C:\Users\pedro\Desktop\Materiapp\api> go mod init github.com/jackc/pgx/v4 go: creating new go.mod: module github.com/jackc/pgx/v4 PS C:\Users\pedro\Desktop\Materiapp\api> go get github.com/jackc/pgx/v4 go: finding module for package github.com/jackc/pgx/v4/pgxpool go: finding module for package github.com/jackc/pgx/v4/pgxpool main.go:8:2: module github.com/jackc/pgx@latest found (v3.6.2+incompatible), but does not contain package github.com/jackc/pgx/v4/pgxpool

How am I supposed to get the v4?

phtdacosta avatar May 12 '20 04:05 phtdacosta

@phtdacosta you pass as argument to go mod init the import path of your project, e.g. go mod init github.com/phtdacosta/helloworld

Afterwards you can run go get github.com/jackc/pgx/v4 to make it available for your project. Then you can start using it by importing the package in your source code. Note that no new files will show up, you can optionally vendor (~download them and include the files in your project) 3. party libraries via go mod vendor

fho avatar May 12 '20 07:05 fho

Hooah! Got that gear working fine now, thank you so much for your support and mainly for your patience with a bare newcomer both on Go and pgx, I am going to dig deeper in the docs as I keep finding any needs. Should I try make a pull request with a mini tutorial towards that point? So other newcomers would not struggle like I did.

phtdacosta avatar May 12 '20 19:05 phtdacosta

looks like this is covered on the wiki now: https://github.com/jackc/pgx/wiki/Getting-started-with-pgx

Zamiell avatar May 16 '20 19:05 Zamiell

Great then! Thank you @Zamiell for pointing out. I think this whole thing is solved then. Thank you guys for all the patience and support!

phtdacosta avatar May 16 '20 22:05 phtdacosta

it would be nice if the installation command go get github.com/jackc/pgx ? will be added to the wiki as well. as a go novice, it is not very straight forward.

darc1 avatar May 25 '20 12:05 darc1

The reason there are no such instructions is it isn't necessary. You don't have to go get pgx. It will be installed automatically if you are using Go modules and you import the package.

https://github.com/jackc/pgx/wiki/Getting-started-with-pgx should provide instructions to start with nothing and end with executing a database query.

jackc avatar May 25 '20 17:05 jackc