rpy2 install on windows 7

2019-01-06 11:45发布

I'm trying to install rpy2 on my computer, but I wasn't able to do it.

I downloaded the source package and I tryed to install Rpy2 (rpy2-2.3.2) using the command python setup.py install. This is the result:

running install
running build
running build_py
running build_ext
"C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config --ldflags
"C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config --cppflags
"C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config LAPACK_LIBS

returned an empty string.

"C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config BLAS_LIBS

returned an empty string.

Configuration for R as a library:
    include_dirs: ('C:/PROGRA~1/R/R-215~1.2/include/i386', 'C:/PROGRA~1/R/R-215~1.2/include')
    libraries: ('R',)
    library_dirs: ('C:/PROGRA~1/R/R-215~1.2/bin/i386',)
    extra_link_args: ()
   # OSX-specific (included in extra_link_args)
    framework_dirs: ()
    framework: ()
building 'rpy2.rinterface._rinterface' extension
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
creating build\temp.win32-2.7\Release\rpy
creating build\temp.win32-2.7\Release\rpy\rinterface
C:\Rtools\gcc-4.6.3\bin\gcc.exe -mcygwin -mdll -O -Wall -DWin32=1 -I.\rpy\rinterface -IC:\Python27\include -IC:\Python27\PC -IC:/PROGRA~1/R/R-215~1.2/include/i386 -IC:/PROGRA~1/R/R-215~1.2/include -c .\rpy\rinterface\_interface.c -o build\temp.win32-2.7\Release\.\rpy\rinterface\_rinterface.o
cc1.exe: error: unrecognized command line option '-mcygwin'
error: command 'gcc' failed with exit status 1

I also tried with build install and easy_install without success. I have R 2.15.2, Python 2.7.2 and Windows 7 (32 bit).

What am I doing wrong?

PS.if I paste that command, the result is:

cygwin warning:

MS-DOS style path detected C:\PROGRA~1\R\R-215~1.2\bin\config.sh
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-215~1.2/bin/config.sh
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

-LC:/PROGRA~1/R/R-215~1.2/bin/i386 -lR

9条回答
劳资没心,怎么记你
2楼-- · 2019-01-06 12:01

I also generally had no success getting Rpy2 to work on Windows. After a few hours hacking around with R2.15 and Rpy2 from the pre-compiled binary 2.3.4.win-amd64-py2.7, I followed this question, and installed pyper instead. Maybe this will work for you until the support is there. I for one would love to see Rpy2 on Windows and IPython notebook (%load_ext rmagic), but I just couldn't spend any more time with it.

查看更多
【Aperson】
3楼-- · 2019-01-06 12:03

Following the answers above, this is what works for me

System: Win 7-64, Python 3.6,

1. Install R and packages you need

2. Set R_HOME and R_USER, as environment variable

R_HOME = D:\Program Files\R\R-3.4.1
R_USER = Administrator 

The user name can be obtained by echo %username% in cmd

3. Download rpy2 and install it

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

Check to its path, and install it in cmd like pip install rpy2-2.8.6-cp36-cp36m-win_amd64.whl

4. Create a notebook and see if it works

import rpy2.robjects as robjects

# test : evaluating R code
robjects.r('''
        # create a function `f`
        f <- function(r, verbose=FALSE) {
            if (verbose) {
                cat("I am calling f().\n")
            }
            2 * pi * r
        }
        # call the function `f` with argument value 3
        f(3)
        ''')
查看更多
霸刀☆藐视天下
4楼-- · 2019-01-06 12:03

Check out this install doc I made about this issue. https://www.academia.edu/12178754/rpy2Install

It's directory specific to an ArcGIS setup, but quick to port

查看更多
欢心
5楼-- · 2019-01-06 12:08

On Anaconda, you can install using:

conda install --channel https://conda.anaconda.org/Richarizardd rpy2

Alternativey, can be tried:

conda install -c r rpy2 

One can also refer:

https://github.com/conda-forge/rpy2-feedstock
查看更多
Fickle 薄情
6楼-- · 2019-01-06 12:11

The install script setup.py is telling that a problem was met when running

"C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config --ldflags

Open a terminal, paste that command, check what the error is.

As you edited the question with the output the problem seems to be that while running that command as a subprocess from python setup.py install an empty string is returned while when running the command from a terminal there is an output. I am also reading from the output from the terminal that cygwin is involved. May be this is the problem ?

查看更多
爷、活的狠高调
7楼-- · 2019-01-06 12:15

OK. From previous experience I've found there are not many instructions on how to install rpy2 on Windows. I get that it's not officially supported but it's really not that hard. In a few steps I'll show what I did and maybe others can follow.

These instructions will most likely only work for Python 2.7+ and R 3.2+ but will probably work for R 3.0+. I am putting the paths that I've used on my system. Make sure to modify the paths accordingly:

First, make sure any previous rpy2 installations are UNINSTALLED before trying these steps (and obviously have R 3.2+ before installing).

  1. Download the .whl file for r2py from here
  2. Install the .whl file using pip install [put .whl filename here] (in the command line) from the directory where the file was downloaded
  3. Append a path similar to C:\Program Files\R\R-3.2.0\bin to your PATH environment variable
  4. Create a R_HOME system variable with a value similar to: C:\Program Files\R\R-3.2.0
  5. Create a R_USER system variable with your user name
  6. Create a R_LIBS_USER system variable with a path to the folder where external R packages are/will be installed.

That's it. Open up a command prompt and enter the command R. This should start an R session and display version information.

Now open up python and run this line to see if things worked out or not:

import rpy2.robjects as robjects 

Hopefully this helps.

查看更多
登录 后发表回答