Python 在 Windows 7 上安装 rpy2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14882477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rpy2 install on windows 7
提问by Luca Chiappi
I'm trying to install rpy2 on my computer, but I wasn't able to do it.
我正在尝试在我的计算机上安装 rpy2,但我无法做到。
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:
我下载了源包,并尝试使用命令安装 Rpy2 (rpy2-2.3.2) python setup.py install。这是结果:
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 installand easy_installwithout success. I have R 2.15.2, Python 2.7.2 and Windows 7 (32 bit).
我也尝试过build install,easy_install但没有成功。我有 R 2.15.2、Python 2.7.2 和 Windows 7(32 位)。
What am I doing wrong?
我究竟做错了什么?
PS.if I paste that command, the result is:
PS.如果我粘贴该命令,结果是:
cygwin warning:
cygwin警告:
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
-LC:/PROGRA~1/R/R-215~1.2/bin/i386 -lR
回答by lgautier
The install script setup.pyis telling that a problem was met when running
安装脚本setup.py告诉运行时遇到问题
"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 --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 installan 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 ?
当您使用输出编辑问题时,问题似乎是当从python setup.py install一个空字符串作为子进程运行该命令时,会返回从终端运行该命令时有一个输出。我也在从终端的输出中读取 cygwin 所涉及的内容。可能是这个问题?
回答by Marcus Jones
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 pyperinstead. 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.
我通常也没有成功让 Rpy2 在 Windows 上工作。在从预编译的二进制文件2.3.4.win-amd64-py2.7 中使用 R2.15 和 Rpy2 进行了几个小时的黑客攻击后,我遵循了这个问题,并安装了pyper。也许这对你有用,直到有支持。我很想在 Windows 和 IPython notebook (%load_ext rmagic) 上看到 Rpy2,但我不能再花时间使用它了。
回答by joon
I just successfully installed rpy2 on Windows 8.1 64bit with the binary installer from http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2. It is usually much easier to just download a binary instead of trying to compile a package in Windows.
我刚刚使用来自http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2的二进制安装程序在 Windows 8.1 64 位上成功安装了 rpy2 。通常只下载二进制文件而不是尝试在 Windows 中编译包要容易得多。
Also, you should set R_HOMEenvironmental variable (in my case, to C:\Program Files\R\R-3.1.1) before you install the rpy2 binary. Otherwise you get RuntimeError: R_HOME not defined.error when you try to import rpy2. (thanks to R_HOME Error with rpy2)
此外,您应该在安装 rpy2 二进制文件之前设置R_HOME环境变量(在我的情况下为C:\Program Files\R\R-3.1.1)。否则,RuntimeError: R_HOME not defined.当您尝试导入 rpy2 时会出错。(感谢rpy2 的 R_HOME 错误)
Lastly, make sure to use %load_ext rpy2.ipythoninstead of %load_ext rmagicif you want to use it in IPython. It is one of the new featuresin rpy2 version 2.4.0.
最后,如果你想在 IPython 中使用它,请确保使用%load_ext rpy2.ipython而不是%load_ext rmagic。它是rpy2 2.4.0 版中的新功能之一。
(thanks to IPython notebook and rmagic/rpy2: cannot find module ri2py (OSX 10.8.5, python 2.7, R 3.1))
(感谢IPython notebook 和 rmagic/rpy2:找不到模块 ri2py (OSX 10.8.5, python 2.7, R 3.1))
回答by Atesh
EDITFinally I managed to get it to work!!! See below:
编辑最后我设法让它工作!!!见下文:
I have been banging my head to get this to work and still haven't figured it out completely. What I have found out is that the error
我一直在努力让这个工作,但仍然没有完全弄清楚。我发现这个错误
'sh' is not recognized as an internal or external command, operable program or batch file
'sh' 不是内部或外部命令,也不是可运行的程序或批处理文件
is caused by the absence of mingw and Rtools (and other unix like helper programs). (http://sourceforge.net/p/rpy/mailman/message/26549197/)
是由于缺少 mingw 和 Rtools(以及其他类似 Unix 的帮助程序)造成的。( http://sourceforge.net/p/rpy/mailman/message/26549197/)
I went passed this stage by installing Rtools (http://cran.r-project.org/bin/windows/Rtools/) and mingw (http://sourceforge.net/projects/mingw-w64/) (But since the mingw-w64 project on sourceforge.net is moving to mingw-w64.org i suggest to use mingw-w64.org)
我通过安装 Rtools ( http://cran.r-project.org/bin/windows/Rtools/) 和 mingw ( http://sourceforge.net/projects/mingw-w64/) (但自从sourceforge.net 上的 mingw-w64 项目正在转移到 mingw-w64.org 我建议使用mingw-w64.org)
I went passed the R.exe CMD config --ldflags error but got stuck with
我通过了 R.exe CMD config --ldflags 错误但被卡住了
TypeError: object of type 'NoneType' has no len()
类型错误:“NoneType”类型的对象没有 len()
error. I am still searching for a solution!!
错误。我还在寻找解决方案!!
Hope this helps someone at some point.
希望这在某些时候可以帮助某人。
UPDATE :So it seems that there are couple of problems associated with the installation. The setup.py is not able to find the correct version of R and the compilers have issues.
更新:所以似乎有几个与安装相关的问题。setup.py 无法找到正确版本的 R 并且编译器有问题。
So, the way to proceed :
所以,继续的方式:
- Download the source code from https://pypi.python.org/pypi/rpy2.
- Update your environment variables - In the user variables
- PATH : append the path to ur R installation eg ;C:\Program Files\R\R-3.0.2\bin\x64
- R_HOME : a new variable with path to R: C:\Program Files\R\R-3.0.2
- R_USER : user user name eg john
- Install Rtools (http://cran.r-project.org/bin/windows/Rtools/) and mingw (http://mingw-w64.org)
around line 123 before
return self._version I added self._version = [3, 0] to force the version to be 3.0 (may be someone can solve this better)
In the file unixccompiler.py either in python27/lib/distutils or in my case C:\Users(user_name)\AppData\Local\Continuum\Anaconda\Lib\distutils comment line 227
- 从https://pypi.python.org/pypi/rpy2下载源代码。
- 更新您的环境变量 - 在用户变量中
- PATH :将路径附加到您的 R 安装中,例如 ;C:\Program Files\R\R-3.0.2\bin\x64
- R_HOME :一个带有 R 路径的新变量:C:\Program Files\R\R-3.0.2
- R_USER : 用户用户名,例如 john
- 安装 Rtools ( http://cran.r-project.org/bin/windows/Rtools/) 和 mingw ( http://mingw-w64.org)
前 123 行左右
返回 self._version 我添加了 self._version = [3, 0] 强制版本为 3.0(可能有人可以更好地解决这个问题)
在文件 unixccompiler.py 中的 python27/lib/distutils 或在我的情况下 C:\Users(user_name)\AppData\Local\Continuum\Anaconda\Lib\distutils 注释行 227
compiler = os.path.basename(sysconfig.get_config_var("CC")) with # (#compiler = os.path.basename(sysconfig.get_config_var("CC")))
编译器 = os.path.basename(sysconfig.get_config_var("CC")) 与 # (#compiler = os.path.basename(sysconfig.get_config_var("CC")))
and add line
并添加行
compiler = 'gcc'
编译器 = 'gcc'
Some other things - use the command prompt cmd for installing. Use
其他一些东西 - 使用命令提示符 cmd 进行安装。用
python setup.py build install
python setup.py 构建安装
Install the Rtools and mingw accepting all defaults. In Rtools select the
安装 Rtools 和 mingw 接受所有默认值。在 Rtools 中选择
extra to build 64 bit R
额外构建 64 位 R
and
和
edit the system PATH
编辑系统路径
Thats it!! Got it to work..
就是这样!!得到它的工作..
Hope this helps!!
希望这可以帮助!!
回答by Jason Matney
Check out this install doc I made about this issue. https://www.academia.edu/12178754/rpy2Install
查看我针对此问题所做的安装文档。https://www.academia.edu/12178754/rpy2Install
It's directory specific to an ArcGIS setup, but quick to port
它是特定于 ArcGIS 设置的目录,但可以快速移植
回答by Atesh
I am not sure if anyone is still following the discussion but in any case, My aim in trying to get rpy2 to work was so to be able to get it working in my Ipython notebooks. If anyone else is trying to do the same, I would suggest using IRkernel which installs smoothly as a cake (well made cake). Here are the resources to get it done. I have used it and it works like a charm.
我不确定是否有人仍在关注讨论,但无论如何,我试图让 rpy2 工作的目标是使其能够在我的 Ipython 笔记本中工作。如果其他人正在尝试做同样的事情,我建议使用 IRkernel,它可以像蛋糕一样顺利安装(制作精良的蛋糕)。这是完成它的资源。我用过它,它的作用就像一个魅力。
basically what you need to run is this:
基本上你需要运行的是:
install.packages(c('rzmq','repr','IRkernel','IRdisplay'),repos = c('http://irkernel.github.io/', getOption('repos')))
IRkernel::installspec()
Here are the resources if you find any troubles:
如果您发现任何问题,这里是资源:
https://github.com/IRkernel/IRkernel
https://github.com/IRkernel/IRkernel
http://blog.revolutionanalytics.com/2015/09/using-r-with-jupyter-notebooks.html
http://blog.revolutionanalytics.com/2015/09/using-r-with-jupyter-notebooks.html
http://www.michaelpacer.com/maths/r-kernel-for-ipython-notebook
http://www.michaelpacer.com/maths/r-kernel-for-ipython-notebook
HTH
HTH
回答by pbreach
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.
好的。根据以前的经验,我发现关于如何在 Windows 上安装 rpy2 的说明并不多。我知道它没有得到官方支持,但真的没有那么难。在几个步骤中,我将展示我所做的,也许其他人可以效仿。
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:
这些说明很可能只适用于 Python 2.7+ 和 R 3.2+,但可能适用于 R 3.0+。我把我在我的系统上使用过的路径。确保相应地修改路径:
First, make sure any previous rpy2 installations are UNINSTALLED before trying these steps (and obviously have R 3.2+ before installing).
首先,在尝试这些步骤之前,确保任何以前的 rpy2 安装都已卸载(并且在安装之前显然有 R 3.2+)。
- Download the .whl file for r2py from here
- Install the .whl file using
pip install [put .whl filename here](in the command line) from the directory where the file was downloaded - Append a path similar to
C:\Program Files\R\R-3.2.0\binto your PATH environment variable - Create a
R_HOMEsystem variable with a value similar to:C:\Program Files\R\R-3.2.0 - Create a
R_USERsystem variable with your user name - Create a
R_LIBS_USERsystem variable with a path to the folder where external R packages are/will be installed.
- 从这里下载 r2py 的 .whl 文件
- 使用
pip install [put .whl filename here](在命令行中)从下载文件的目录安装 .whl 文件 - 附加类似于
C:\Program Files\R\R-3.2.0\bin您的 PATH 环境变量的路径 - 创建一个
R_HOME系统变量,其值类似于:C:\Program Files\R\R-3.2.0 R_USER使用您的用户名创建系统变量- 创建一个
R_LIBS_USER系统变量,其中包含安装/将安装外部 R 包的文件夹的路径。
That's it. Open up a command prompt and enter the command R. This should start an R session and display version information.
就是这样。打开命令提示符并输入命令R。这应该启动 R 会话并显示版本信息。
Now open up python and run this line to see if things worked out or not:
现在打开 python 并运行这一行,看看事情是否成功:
import rpy2.robjects as robjects
Hopefully this helps.
希望这会有所帮助。
回答by Manoj Kumar
On Anaconda, you can install using:
在 Anaconda 上,您可以使用以下命令进行安装:
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
回答by cqcn1991
Following the answers above, this is what works for me
按照上面的答案,这对我有用
System: Win 7-64, Python 3.6,
系统:Win 7-64,Python 3.6,
1. Install R and packages you need
1.安装R和你需要的包
2. Set R_HOMEand R_USER, as environment variable
2. 设置R_HOMEand R_USER, 作为环境变量
R_HOME = D:\Program Files\R\R-3.4.1
R_USER = Administrator
The user name can be obtained by echo %username%in cmd
用户名可以通过echo %username%在cmd中获取
3. Download rpy2and install it
3.下载rpy2并安装
Download rpy2 from http://www.lfd.uci.edu/~gohlke/pythonlibs/
从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载 rpy2
Check to its path, and install it in cmd like pip install rpy2-2.8.6-cp36-cp36m-win_amd64.whl
检查其路径,并将其安装在 cmd 中,例如 pip install rpy2-2.8.6-cp36-cp36m-win_amd64.whl
4. Create a notebook and see if it works
4.创建一个笔记本,看看它是否有效
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)
''')

