install rpy2 on Windows7 64bit for Python 2.7

2019-02-21 15:39发布

问题:

I am trying to build and install rpy2 Python Module. But got an error (see below).

I have R installed in C:\Program Files\R\R-2.15.0\ and R.h is in C:\Program Files\R\R-2.15.0\include. How can I tell setup.py to find the R header in that directory?

Both Python and R were installed using official binary file for Windows 64bit.

Can someone contribute a rpy2 binary build for windows 64bit and Python2.7 64bit? Christoph Gohlke said for legal or technical reasons, rpy2 is not included in his Unofficial Windows Binaries for Python Extension Packages. Anyone else has a successful hit?

Thanks!

Given the following process:

$ python setup.py  build
running build
running build_py
running build_ext

returned an empty string. (5 times)

With this configuration for R as a library:

include_dirs: ()
libraries: ()
library_dirs: ('C:/PROGRA~1/R/R-215~1.0/bin/i386',)
extra_link_args: ()
 # OSX-specific (included in extra_link_args)
  framework_dirs: ()
  frameworks: ()

building 'rpy2.rinterface._rinterface' extension, using this command:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c 
/nologo /Ox /MD /W3 /GS- /DNDEBUG -DWin32=1 -DCSTACK_DEFNS=1 
-I.\rpy\rinterface -IC:\Python27\include -IC:\Python27\PC 
/Tc.\rpy\rinterface\_rinterface.c 
/Fobuild\temp.win-amd64-2.7\Release\.\rpy\rinterface\_rinterface.obj
_rinterface.c

gives this error:

.\rpy\rinterface\_rinterface.c(61) : fatal error C1083: Cannot open include file: 
'R.h': No such file or directory
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe"' 
failed with exit status 2

回答1:

Here's a link to the rpy2 Windows binaries, all Python versions and x86/x64:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2



回答2:

My experience (2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)]): - all binary installers - apparently rpy2 has unspecified dependencies - have numpy and scipy installed (win_amd64 binaries) with their unspecified dependencies

  1. install R, install needed packages
  2. install pywin32
  3. "pip install singledispatch"
  4. "pip install rpy2-2.5.6-cp27-none-win_amd64.whl"
  5. update environment, e.g. os.environ['R_HOME'] = r'C:\Program Files\R\R-3.1.3' os.environ['R_USER'] = r'C:\Python27\Lib\site-packages\rpy2'


回答3:

I am working through the same myself. The libraries etc. Located indicate that you are picking up the 32 bit version i386. Add "C:\Program Files\R\R-2.15.1\include" include directory may help force fix the problem. This is the farthest I have got:

building 'rpy2.rinterface._rinterface' extension
error: Unable to find vcvarsall.bat

With the MSVC express shell and R x64 and msys sh in path.



回答4:

This link to the binary file works for me, I hope others find it useful: link to the binary



回答5:

I tried all of these on my Windows 10 and got nowhere. When I did the pip, it said it was installed into the Anaconda version that I have been using for months, but when I tried an import rpy, it just gave an error.

Was going to give up, but then I slept on it a night and then I did the following from the command line:

  • Deleted all my old Python instances including Anaconda
  • Rebooted
  • Reinstalled Anaconda (2.4.1 with Python version 2.7.11)
  • Made sure python ran from the command line from any directory
  • started my "mingw32" bash shell (the one that comes with git)
  • Set my personal R_HOME environment variable to C:\Program Files\R\R-3.2.3
  • Downloaded rpy2-2.7.5-cp27-none-win_amd64.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2 as suggested above.
  • Changed the working directory to my user Downloads directory
  • Installed it with pip install rpy2-2.7.5-cp27-none-win_amd64.whl
  • Started python and successfully imported and rn py2

Here is a screen capture of the final steps:

mwise@MWISE-OPTO ~/Downloads
$ pip install rpy2-2.7.5-cp27-none-win_amd64.whl
Processing c:\users\mwise\downloads\rpy2-2.7.5-cp27-none-win_amd64.whl
Requirement already satisfied (use --upgrade to upgrade): six in c:\users\mwise\appdata\local\continuum\anaconda2\lib\site-packages (from rpy2==2.7.5)
Requirement already satisfied (use --upgrade to upgrade): singledispatch in c:\users\mwise\appdata\local\continuum\anaconda2\lib\site-packages (from rpy2==2.7.5
)
Installing collected packages: rpy2
Successfully installed rpy2-2.7.5

mwise@MWISE-OPTO ~/Downloads
$ python
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  7 2015, 14:10:42) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import rpy2
>>> import rpy2.robjects as robjects
>>> pi = robjects.r['pi']
>>> pi[0]
3.141592653589793
>>>

Hoping this will help someone down the line...



回答6:

This is because your R include library is not in your CPPFLAGS enviroment variable. You should find the file R.h in your "C:\Program Files\R\R-2.15.0\include". In linux, you can add this to your .bashrc

export "$CPPFLAGS=-I/path-to-R/include $CPPFLAGS"

But i'm not familar to python and R in windows. That's all I can help.