'Error Installing psycopg2 on Amazon Linux
When installing psycopg2 on Amazon Linux using this command: sudo pip-3.4 install psycopg2 I get this output:
gcc -pthread -Wno-unused-result -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7 (dt dec pq3 ext)" -DPG_VERSION_NUM=90218 -I/usr/include/python3.4m -I. -I/usr/include/pgsql92 -I/usr/include/pgsql92/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.4/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from ./psycopg/replication_cursor.h:30:0,
from psycopg/psycopgmodule.c:32:
./psycopg/libpq_support.h:31:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘XLogRecPtr’
typedef unsigned PG_INT64_TYPE XLogRecPtr;
^
In file included from psycopg/psycopgmodule.c:32:0:
./psycopg/replication_cursor.h:47:5: error: unknown type name ‘XLogRecPtr’
XLogRecPtr write_lsn; /* LSNs for replication feedback messages */
^
./psycopg/replication_cursor.h:48:5: error: unknown type name ‘XLogRecPtr’
XLogRecPtr flush_lsn;
^
./psycopg/replication_cursor.h:49:5: error: unknown type name ‘XLogRecPtr’
XLogRecPtr apply_lsn;
^
In file included from psycopg/psycopgmodule.c:33:0:
./psycopg/replication_message.h:46:5: error: unknown type name ‘XLogRecPtr’
XLogRecPtr data_start;
^
./psycopg/replication_message.h:47:5: error: unknown type name ‘XLogRecPtr’
XLogRecPtr wal_end;
^
error: command 'gcc' failed with exit status 1
I already have gcc, postgresql-devel, postgresql-libs, and python34-devel installed. Am I missing a package or setting?
Edit: This is on an EMR node.
Solution 1:[1]
I have the same problem with EMR, I tried below
sudo yum -y install gcc python-setuptools python-devel postgresql-devel
sudo /usr/bin/pip install --upgrade pip
sudo /usr/local/bin/pip install psycopg2
It works when I'm running it on EMR but doesn't work when EMR is spin up from Pipeline.
Solution 2:[2]
If you are trying to install psycopg2 for python3 you must install python3-devel as well.
To find the correct package
yum search python3 | grep devel
In my case it was python36-devel so I did
sudo yum install python36-devel
And then I could install psycopg2 for my python3 virtualenvironment on the machine
Solution 3:[3]
If you're looking for psycopg2 for python3 in amazon linux, this is what worked for me:
sudo yum install -y gcc postgresql-devel
sudo curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python36
sudo pip-3.6 install -U psycopg2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 1EnemyLeft |
| Solution 2 | Mazvél |
| Solution 3 | geekjimbo |
