在 windows 上安装 rpy2

Installing rpy2 on windows

我正在尝试在机器上安装 rpy2 运行 Windows 10. 我已经安装了 R 3.4.4(64 位)并且它在 RGui 中运行良好。然后我尝试 pip install rpy2,但出现找不到 R 的错误,因此我将 c:\Program Files\R\R-3.4.4\bin\ 添加到我的路径环境变量中。现在我做的时候

pip install rpy2

我得到一个不同的错误:

Command '('c:\PROGRA~1\R\R-34~1.4\bin\x64\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 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\

输出包含错误:

'sh' is not recognized as an internal or external command

但我认为这只是一个警告(因为它后面有输出)。 sh (shell) 是 Nix 特定的并且(自然地)不存在于。但是,如果您为 WinLnx env 模拟器安装端口(例如 Cygwin),它可能会起作用。

这是 [ReadTheDocs.rpy2]: Installation 的内容(其中包含“在 Linux 上编译”和“在 OS 上编译 X”部分,但与 Win 无关,尽管它提到它应该编译成功)指出:

  • There is currently no binaries or support for Microsoft Windows (more for lack of resources than anything else).

  • Microsoft’s Windows - unofficial and unsupported binaries are provided by Christoph Gohlke (http://www.lfd.uci.edu/~gohlke/pythonlibs); there is otherwise currently close to no support for this platform



更新#0

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

  • 从 [=17= 下载 rpy2‑2.9.3‑cp35‑cp35m‑win_amd64.whl(或可能同时添加的任何更新版本) ](对于32位,下载*win32.whl
  • .whl[=63=中打开一个cmdwindow(作为管理员) ]的下载目录
  • R_USERenv var设置为当前用户名:set R_USER=%USERNAME%
  • python -m pip install rpy2‑2.9.3‑cp35‑cp35m‑win_amd64.whlPython的(二进制)dir必须在 %PATH%,或指定完整路径)