23

I have R (3.1.1) and PostgreSQL 9.4 installed on Debian 7.6.

I want to install RPostgreSQL but the compilation fails with the following error:
In file included from RS-PQescape.c:7:0:                                       
RS-PostgreSQL.h:23:26: fatal error: libpq-fe.h: No such file or directory      
compilation terminated.                                                        
make: *** [RS-PQescape.o] Error 1                                              
ERROR: compilation failed for package ‘RPostgreSQL’                            
* removing ‘/home/mert/R/x86_64-pc-linux-gnu-library/3.1/RPostgreSQL’          

A previous question on this error says that the file is included here:

/usr/pgsql-9.3/include/libpq-fe.h

I searched on my computer for pgsql and libpq but no such file exists at all:

$ locate libpq                              
/usr/lib/postgresql/9.4/lib/libpqwalreceiver.so                                
/usr/lib/x86_64-linux-gnu/libpq.so.5                                           
/usr/lib/x86_64-linux-gnu/libpq.so.5.7                                         
/usr/share/doc/libpq5 

$ locate pgsql
/usr/lib/postgresql/9.4/lib/plpgsql.so                                         
/usr/share/postgresql/9.4/extension/plpgsql--1.0.sql                           
/usr/share/postgresql/9.4/extension/plpgsql--unpackaged--1.0.sql               
/usr/share/postgresql/9.4/extension/plpgsql.control  

Do you have any idea on how to solve this problem?

Community
  • 1
  • 1
Mert Nuhoglu
  • 9,695
  • 16
  • 79
  • 117

4 Answers4

52

You are missing libpq-dev on your machine. Open a command prompt and install it using apt-get. Once installed try installing RPostgreSQL in R-Studio.

sudo apt-get install libpq-dev

Or for Arch Linux:

sudo pacman -S postgresql-libs
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
smishra
  • 3,122
  • 29
  • 31
4

Adding to the previous answers, in case of errors even when libpq-dev is already installed. On Ubuntu 16.04 with installed libpq-dev, my libpq-fe.h was sitting in /usr/include/postgresql/ but the R install packages function still could not find it. After downloading the latest RPostgreSQL build from CRAN, I looked at its configure file and saw that this folder was specified in it as a likely location for the postgres configuration files which led me to believe that it was a permissions problem, and, yes,

sudo R CMD INSTALL RPostgreSQL_0.4-1.tar.gz 

solved the situation.

Adam
  • 337
  • 3
  • 10
2

I was able to install RPostgreSQL on Ubuntu 14.04 using the following:

system('gksudo "apt-get -y install postgresql-9.3 libpq-dev"')
install.packages("RPostgreSQL")
dnlbrky
  • 9,396
  • 2
  • 51
  • 64
2

You should install

apt-get install libpq-dev

But if you get an error like:

libpq-dev : Depends: libpq5 (= 12.8-0ubuntu0.20.04.1) but 14.0-1.pgdg20.04+1 is to be installed

You should install first (look carefully at the name above):

apt-get install libpq5=12.8-0ubuntu0.20.04.1

and then apt-get install libpq-dev again.

Emeeus
  • 5,072
  • 2
  • 25
  • 37