Rpy2 is the R language interface module in Python, today, a afternoon, and finally put Rpy2, record the installation process need to pay attention to the problem:
1. During the R compilation process, the--enable-r-shlib option must be selected to compile R into the Lib mode, in which case the path-to-r/lib/libr.so library is generated;
At the same time, ensure that the same directory librblas.so, librlapack.so two linked libraries are also generated correctly, the two libraries are generated by default, if not, you need to add parameters:--enable-blas-shlib--with-blas-- With-lapack
Cannot compile correctly if build Libr.so,rpy2 is not compiled
2. After the installation of R is complete, if you install to a personal path, you need to add four environment variables to the configuration file:
Export R_home=path-to-r
Export r_libs= $R _home/lib64/r/library
Export ld_library_path= $R _home/lib: $LD _library_path
Export path= $R _home/bin: $PATH
It is easier to miss the PATH and Ld_library_path, if it is installed with root, there may be no problem, if installed in the personal directory, do not add these two variables, will not be able to correctly find the required dynamic link library;
The function of R_libs is to find the corresponding package according to the RPY2 when the installed R package is called.
3. Python must install Sqlite-devel before compiling the installation, otherwise it will not find the error message of the _sqlite module.
If you have already installed Python, you will need to install the Sqlite-devel library and reinstall Python;
Make sure the above three points are no problem, RPY2 installation is relatively simple, direct use
Pip Install Rpy2
Can
Check that the RPY2 is installed correctly:
>>> Import Rpy2.robjects as RB
>>> RB.R ("library (' Ade4 ')")
<StrVector-Python:0x7fccfd2a2248/R:0x2e44108>
[STR, str, str, ..., str, str, STR]
Ensure that there are no warning messages and error messages, the RPY2 is installed successfully and the installed R packages can be called correctly.
Rpy2 problems in installation and use