Ansible pip installing psycopg2 from source when binary requested

i’m trying to install psycopg2-binary but when i do it via ansible it attempts to install from source, even though i’m outright requesting the binary package

from the terminal, the following works just fine and installs the binary package
sudo pip3 install psycopg2-binary

when using the pip module it attempts to install from source and then cries about dependencies it can’t find.

    - name: install psycopg2-binary
      pip:
        name: psycopg2-binary
      become: yes

i’ve also tried calling it from command just like at the terminal and this also results in it getting installed from source

    - name: install psycopg2-binary
      command: "pip3 install psycopg2-binary"
      become: yes

ansible core 2.15.12
target system RHEL8, python3.8

If you are on RHEL, would using the dnf module be better?

I suggest this, after reading stackoverflow

This isn’t just CentOS, I think. psycopg has native dependencies, so to build from source (which is what pip does), the PostgreSQL development libraries need to be there. (The C headers, maybe? I don’t know much about compiling native code.)

1 Like

thanks gundalow! being sort of a noob i just followed all the instructions i saw online which directed install using pip. installing with dnf never occurred to me.
that did resolved the issue.

i’m still rather confused why manual pip at the terminal installs the binary version fine while calling pip via ansible installs from source if anyone has an answer for that

Glad you got it working.

If you run pip directly on the system it will likely fail as well. From that stackoverflow article is seems like the package is always built from source, so your system is likely missing some other dependencies.

if i run pip directly on the system it works just fine, that’s where my confusion comes in. i did look at the article and noted they were having the issue running pip directly but that is not the case in my situation. guess it will remain an unsolved mystery. thanks again for the workaround.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.