Question

I got an error in R when building the rPython package, specifically the part that links against libpython2.7:

gcc -std=gnu99 -I/foo/bar/R-3.1.1/lib64/R/include -DNDEBUG  -I/usr/local/include \
  -I/foo/bar/Python-2.7.6/include/python2.7 -I/foo/bar/Python-2.7.6/include/python2.7 \
  -D PYTHONLIBFILE=libpython2.7.so -fpic  -g -O2  -c pycall.c -o pycall.o

gcc -std=gnu99 -shared -L/usr/local/lib64 -o rPython.so pycall.o \
  -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic

/usr/bin/ld: error: cannot find -lpython2.7

The problem seems to be that while R (or rPython) understood which -I rules to compile with my Python installation, it did not add the corresponding linker flags. I don't know why, suppose it's a bug.

Was it helpful?

Solution 2

I fixed it using information from here: http://carlo-hamalainen.net/blog/2012/5/11/r-makeflags-rpath-and-building-packages

Before running R to do install.packages('rPython'), do this:

export MAKEFLAGS='LDFLAGS=-L/foo/bar/Python-2.7.6/lib\ -Wl,-rpath\ /foo/bar/Python-2.7.6/lib'

Note the backslash-escaped spaces. Now you can run R and install rPython. Once it's installed you don't need MAKEFLAGS anymore.

OTHER TIPS

I had also the same problem and I could solve it simply by installing python-dev package, I saw it in some forums to be honest.

You can install this from the terminal using:

sudo apt-get install python-dev

and then re-try to install rPython again.

It worked for me!

I received the exact same error when trying to install rPython, but my situation was complicated by the fact that I needed to link rPython to a specific python environment rather than the default system version.

The system's default python was 2.6, which seems to have caused problems when trying to link it to my custom 2.7, even with MAKEFLAGS and the RPYTHON_PYTHON_VERSION environment variable (rPython using wrong python installation on Mac OSX) set. My guess is that rPython defaulted to my system's python 2.6 even when giving it MAKEFLAGS. Setting RPYTHON_PYTHON_VERSION=2 or RPYTHON_PYTHON_VERSION=2.7 caused R to complain:

which: no python2.7-config in [long, redacted $PATH]
could not locate python2.7-config
ERROR: configuration failed for package 'rPython'

The solution in my case was to create a python 3 environment and use both MAKEFLAGS and RPYTHON_PYTHON_VERSION, i.e.:

export RPYTHON_PYTHON_VERSION=3
MAKEFLAGS='LDFLAGS=-L/foo/bar/Python-3.4.3/lib\ -Wl,-rpath\ /foo/bar/Python-3.4.3/lib' R CMD INSTALL ~/rPython_0.0-5.tar

This took me much too long to figure out; hopefully this can help someone in a similar situation.

Thanks for the response John.

A quick note for those using the anaconda distribution:

$ export MAKEFLAGS='LDFLAGS=-L/home/USERNAME/anaconda2/pkgs/python-2.7.12-1/lib\ -Wl,-rpath\ /home/USERNAME/anaconda2/pkgs/python-2.7.12-1/lib'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top