Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the different about psycopg2 and psycopg2-binary python package

Tags:

python-3.x

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.

like image 211
Dolphin Avatar asked Aug 31 '25 15:08

Dolphin


2 Answers

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

like image 65
Zed Avatar answered Oct 14 '25 06:10

Zed


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

like image 39
raphael obinna Avatar answered Oct 14 '25 05:10

raphael obinna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!