5

I am having trouble installing the Python package rpy2. I have already compiled R as a shared library, but I do not have admin priviledges so I am trying to install rpy2 with:

pip install -user rpy2

However, I am getting the following error:

./rpy/rinterface/_rinterface.c:86:31: fatal error: readline/readline.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

I have downloaded readline to:

/some/path/readline-6.2/

where I can see readline.h (I have also compiled readline just in case)

My question:

How can I make rpy2 (or pip) aware of this location with readline.h to avoid the header compilation error?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

4 Answers4

2

You'll need to actually install readline, not just download it, and then point rpy2 to it with CFLAGS and LDFLAGS.

Try this approach. It's almost working for me - I have the same problem, except an additional wrinkle that rpy2 seems to be linking against the system R instead of my homedir install.

First, I downloaded readline to ~/src/readline-6.2, and installed it with ./configure --prefix=$HOME && make && make install. (You need to install it somewhere, not just download the source.)

Then I re-compiled R with

CPPFLAGS="-I/usr/local/include -I$HOME/include/" \
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -L$HOME/lib64 -L$HOME/lib" \
./configure --prefix=$HOME --enable-BLAS-shlib --enable-R-shlib
make
make install

R is definitely now using that readline:

$ ldd ~/lib64/R/lib/libR.so | grep readline
libreadline.so.6 => /home/dsutherl/lib/libreadline.so.6 (0x00007f8104207000)

The same for my in-home install of Python (3.2.3, since h5py doesn't work with 3.3 yet):

CFLAGS="-I/usr/local/include -I$HOME/include/" \
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -L$HOME/lib64 -L$HOME/lib" \
./configure --prefix=$HOME
make
make install

And again:

$ ldd ~/lib/python3.2/lib-dynload/readline.cpython-32m.so | grep readline
libreadline.so.6 => /home/dsutherl/lib/libreadline.so.6 (0x00007fbfff5c2000)

Then I downloaded the rpy2 source and built that:

CFLAGS="-I/usr/local/include -I$HOME/include/" \
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -L$HOME/lib64 -L$HOME/lib" \
python3 setup.py build --r-home $HOME/lib64/R install

This seemed successful, and ldding the .sos in site-packages/rpy2 links to the right libreadline...but to the system R, instead of mine, despite the explicit --r-home.

Danica
  • 28,423
  • 6
  • 90
  • 122
  • Thanks Dougal. I followed these steps but somehow I am still suffering from the problem `/path/to/python2.7/site- packages/rpy2/rinterface/_rinterface.so: undefined symbol: Rf_translateCharUTF8` By the way, I think that your error is possibly due to the fact that Rpy2 looks up R from `$PATH`, and it tries to infer the R home directory from it. If you update `$PATH` to make sure it sees `$HOME/bin/` before the system PATH you should be fine – Amelio Vazquez-Reina Jun 26 '13 at 23:29
1

more simple :

yum install readline-devel.x86_64

run for me on centos 7

for debian/ubuntu

apt-get install libreadline-dev
alex
  • 10,900
  • 15
  • 70
  • 100
-2

Sometime in linux is needed an sudo apt-get upgrade, to get the news libraries, may work

lindosekai
  • 174
  • 8
-2

This is another option, but too you need root privilegies ... sudo apt-get install libreadline-dev

lindosekai
  • 174
  • 8