在windows上安装rpy2

时间:2018-04-19 07:58:07

标签: python rpy2

我正在尝试在运行Windows 10的计算机上安装rpy2。我已经安装了R 3.4.4(64位),它在RGui中工作正常。然后我尝试pip安装rpy2,但是收到了一个无法找到R的错误,所以我将c:\ Program Files \ R \ R-3.4.4 \ bin \添加到我的路径环境变量中。现在我做的时候

pip install rpy2

我得到了一个不同的错误:

  

命令'('c:\ PROGRA~1 \ R \ R-34~1.4 \ bin \ x64 \ R','CMD','config',' - oldflags')'返回非零退出状态1

完整输出如下。知道我做错了吗?

pip install rpy2

Collecting rpy2
  Downloading https://files.pythonhosted.org/packages/88/f7/788e5e1587bc1ab48b5b0467f9c3a08ef5aadbd993ed835559a10e452121/rpy2-2.9.3.tar.gz (193kB)
Complete output from command python setup.py egg_info:
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.

'sh' is not recognized as an internal or external command,
operable program or batch file.
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
c:\PROGRA~1\R\R-34~1.4\bin\x64\R CMD config --ldflags
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\py\AppData\Local\Temp\pip-build-qz4rb_4o\rpy2\setup.py", line 374, in <module>
    ri_ext = getRinterface_ext()
  File "C:\Users\py\AppData\Local\Temp\pip-build-qz4rb_4o\rpy2\setup.py", line 269, in getRinterface_ext
    ldf = shlex.split(' '.join(rexec.cmd_config('--ldflags')))
  File "C:\Users\py\AppData\Local\Temp\pip-build-qz4rb_4o\rpy2\setup.py", line 222, in cmd_config
    universal_newlines = True)
  File "c:\users\py\miniconda3\lib\subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "c:\users\py\miniconda3\lib\subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('c:\\PROGRA~1\\R\\R-34~1.4\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 1

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\py\AppData\Local\Temp\pip-build-qz4rb_4o\rpy2\

1 个答案:

答案 0 :(得分:2)

是的,您的输出包含错误:

  

'sh'未被识别为内部或外部命令

但我认为这只是一个警告(因为它后面有输出)。 sh Ux 特定的( shell )并且(自然地) Win 上不存在。但是,如果为 Win Lnx env模拟器(如Cygwin)安装端口,则可能会有效。

以下是[ReadTheDocs.rpy2]: Installation(其中“在Linux上编译”和“在OS X上编译”部分,但没有关于 Win ,虽然它提到它应该成功编译)状态:

  •   

    目前没有Microsoft Windows的二进制文件或支持(更多是因为缺少资源而不是其他任何内容)。

  •   

    微软的Windows - 非官方和不受支持的二进制文件由Christoph Gohlke(http://www.lfd.uci.edu/~gohlke/pythonlibs)提供;否则目前几乎不支持这个平台

<强> @ EDIT0

添加@pyguy采取的步骤(来自评论),以便成功安装 rpy2

  • [uci]: Unofficial Windows Binaries for Python Extension Packages下载 rpy2-2.9.3-cp35-cp35m-win_amd64.whl
  • 在下载目录中打开 cmd 窗口(管理员
  • %R_USER% env var设置为当前用户名:set R_USER=%USERNAME%
  • pip install rpy2‑2.9.3‑cp35‑cp35m‑win_amd64.whl pip 的目录必须在%PATH%中)