I set up a project on my old laptop with Postgresql installed on my local, and use Poetry as packages manager. Now I move into another laptop. On this one, I want to use Postgres from Docker so I didn’t install it. But when I run poetry install
to set up project from poetry.lock
file, It cannot install Psycopg2 with the error:
Error: pg_config executable not found.
As I searched, It requires Postgres to be installed locally. So, how can I install Psycopg2 from the lock file with Postgres from Docker?
2
Answers
PostgreSQL(development or any stable version) should be installed before installing psycopg2. You are planning to use the database server from docker which is perfectly fine. But, to install psycopg2, you need to have Postgres installed in your host machine. However, it is not required in host machine when you run the application in docker as well. You can check this answer to get help on installing psycopg2 in your OS.
You don’t need to install Postgres itself, but you need libpq.
Therefore, the pyscopg2 documentation recommends installing the packages
python3-dev
andlibpq-dev
.The below is written in their docs:
If you don’t want that, you can use the pre compiled binary via the python package
psycopg2-binary
, although it’s not really recommended.