Installing rpy2 2.3.x and numpy on RHEL6

R from EPEL has been updated to version 3.

We would like to run rpy2 but as of rpy2 version 2.3.x, it requires Python 2.7.

Red Hat Enterprise Linux 6 comes with Python 2.6.

So we need Python 2.7 so we can use rpy2 2.3 so we can use R 3.

The solution is to create a Python virtualenv containing Python 2.7 and install rpy2 in there. That way a user can log in and get Python 2.7 when they type python at the command line.

Take a moment to make sure standard build tools are installed. At a minimum, we need the following since we want numpy to use ATLAS, BLAS, and LAPACK, and not run into problems using SSL from Python:

yum install -y gcc atlas-devel blas-devel lapack-devel openssl-devel

Python 2.7 can now be installed from source:

curl -O http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar xvzf Python-2.7.3.tgz
cd Python-2.7.3
./configure --enable-shared
make altinstall
echo "/usr/local/lib" > /etc/ld.so.conf.d/python2.7.conf
ldconfig

Now setuptools:

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.9.8.tar.gz
tar xvfz setuptools-0.9.8.tar.gz
cd setuptools-0.9.8
/usr/local/bin/python2.7 setup.py build
/usr/local/bin/python2.7 setup.py install --record installedfiles.txt

Finally, virtualenv. This installs the virtual environment at /usr/local/ve but you might want it elsewhere.

wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz
tar xvfz virtualenv-1.9.1.tar.gz
cd virtualenv-1.9.1
python2.7 setup.py install --record installedfiles.txt
virtualenv-2.7 /usr/local/ve
source /usr/local/ve/bin/activate

That last line activates the virtual environment, so adding it to your .bash_profile might be handy.

Trying to add numpy with easy_install-2.7 didn't work for me:

(ve)[snorky]# easy_install-2.7 numpy
...
Running numpy-1.7.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-u0mtJj/numpy-1.7.1/egg-dist-tmp-kGRfag
Running from numpy source directory.
error: SandboxViolation: open('/dev/null', 'w') {}

The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.

This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand.  Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.

However, pip worked like a charm:

(ve)[snorky]# pip install numpy
...
(ve)[snorky]$ python
Python 2.7.3 (default, Jul 29 2013, 17:08:17)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy

Likewise rpy2 worked fine:

pip install rpy2
...

(ve)[snorky]# python
Python 2.7.3 (default, Jul 29 2013, 17:08:17)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2
>>> import rpy2.rinterface

Reference: Undefined symbol (Rf_PrintWarnings) when using rpy 2.3.1 and R 3.0.1

Topic: