Pgx: How to install that package?

Created on 11 May 2020  路  11Comments  路  Source: jackc/pgx

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.

All 11 comments

@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 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

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.

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

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 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

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.

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

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!

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrdulin picture mrdulin  路  4Comments

Zamiell picture Zamiell  路  10Comments

Nokel81 picture Nokel81  路  6Comments

badoet picture badoet  路  10Comments

hgl picture hgl  路  6Comments