Today I found the python connect postgresql have psycopg2 and psycopg2-binary package, which one should I choose? what is the difference with the two package? seems no one talk about the diff about it.Seems psycopg2 are hard to install because of the dependencies. psycopg2-binary easy to install but weak with the ability.
The difference between the two is that
the binary package is a practical choice for development and testing but in production it is advised to use the package built from sources, whereas
building psycopg requires a few prerequisites (a C compiler, some external development library packages)
Read more at psycopg2 documentation on Python's Package Index (PyPI) projects website
if you want to build an image of your app that uses psycopg2, you also have to install the dependencies for it. but with psycopg2-binary, you don't need these dependencies written in C.
To add to your dockerfile the code to setup the essential dependencies for your psycopg2 library. You can add
RUN apt-get update \ && apt-get install -y build-essential libpq-dev gcc \ && rm -rf /var/lib/apt/lists/*
For reference the official documentation - https://www.psycopg.org/docs/install.html#build-prerequisites
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With