I've been trying to install the rpy2 module so I can use R functions inside my Python script, but I'm getting an error after following the advice from these pages:
我一直在尝试安装rpy2模块,这样我就可以在Python脚本中使用R函数了,但是在遵循了这些页面的建议之后,我得到了一个错误:
1) Tried to guess R's HOME but no R command in the PATH. OsX 10.6
1)尝试猜测R的家,但是路径中没有R命令。OsX 10.6
2) http://rpy.sourceforge.net/rpy2/doc-dev/html/overview.html
2)http://rpy.sourceforge.net/rpy2/doc-dev/html/overview.html
What I've done so far:
到目前为止我所做的:
1) Edited my path environment variable to include "C:\Program Files\R\R-3.1.0\bin\x64;"
1)编辑了我的path环境变量,其中包含“C:\程序文件\R\R-3.1.0\bin\ bin\ \bin\x64”;
2) Created a new environment variable called "R_HOME" and set its value to "C:\Program Files\R\R-3.1.0"
2)创建了一个名为“R_HOME”的新环境变量,并将其值设置为“C:\程序文件\R-3.1.0”
3) Created a new environment variable called "R_USER" and set its value to "Hefin" (my windows username)
3)创建一个名为“R_USER”的新环境变量,并将其值设置为“Hefin”(我的windows用户名)
Then in my command prompt I type:
然后在命令提示符中输入:
easy_install rpy2
As far as I'm aware, easy_install is setup and installed correctly.
据我所知,easy_install安装和安装都是正确的。
The output I get is:
我得到的输出是:
Searching for rpy2
Reading https://pypi.python.org/simple/rpy2/
Best match: rpy2 2.5.5
Downloading https://pypi.python.org/packages/source/r/rpy2/rpy2-2.5.5.tar.gz#md5=c874bebbe775e3cdc926a1da00252c37
Processing rpy2-2.5.5.tar.gz
Writing C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.cfg
Running rpy2-2.5.5\setup.py -q bdist_egg --dist-dir C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\egg-dist-tmp-00qpf_z8
The system cannot find the path specified.
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 150, in save_modules
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 191, in setup_context
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 235, in run_setup
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 265, in run
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 234, in runner
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 46, in _execfile
File "C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.py", line 282, in <module>
File "C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.py", line 185, in getRinterface_ext
File "C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.py", line 106, in version
File "C:\Python34\lib\subprocess.py", line 620, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command '('C:\\PROGRA~1\\R\\R-31~1.0\\bin\\R', '--version')' returned non-zero exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\Scripts\easy_install-script.py", line 9, in <module>
load_entry_point('setuptools==12.0.5', 'console_scripts', 'easy_install')()
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 2244, in main
File "C:\Python34\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 374, in run
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 623, in easy_install
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 653, in install_item
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 838, in install_eggs
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 1066, in build_and_install
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\command\easy_install.py", line 1052, in run_setup
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 238, in run_setup
File "C:\Python34\lib\contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 191, in setup_context
File "C:\Python34\lib\contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 162, in save_modules
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 137, in resume
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\compat.py", line 65, in reraise
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 150, in save_modules
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 191, in setup_context
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 235, in run_setup
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 265, in run
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 234, in runner
File "C:\Python34\lib\site-packages\setuptools-12.0.5-py3.4.egg\setuptools\sandbox.py", line 46, in _execfile
File "C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.py", line 282, in <module>
File "C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.py", line 185, in getRinterface_ext
File "C:\Users\Hefin\AppData\Local\Temp\easy_install-98mu0_xn\rpy2-2.5.5\setup.py", line 106, in version
File "C:\Python34\lib\subprocess.py", line 620, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command '('C:\\PROGRA~1\\R\\R-31~1.0\\bin\\R', '--version')' returned non-zero exit status 1
C:\Users\Hefin>
Sorry it's so verbose! If I then invoke python and try to import the rpy module, I get:
对不起这么详细!如果我然后调用python并尝试导入rpy模块,我得到:
>>> import python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'python'
>>>
I'm afraid I'm new to Python and I don't know what I'm doing wrong. I've searched through previous forum posts, but none seem to have this problem. I'm using a 64bit machine with Windows 7, Python3.4 and R3.1.0.
我恐怕是Python的新手,我不知道我做错了什么。我搜索过以前的论坛帖子,但似乎没有一个人有这个问题。我使用的是一台64位的机器,有Windows 7、Python3.4和R3.1.0。
Any help or thoughts would be much appreciated as I'm sure it's just something simple I'm doing wrong.
任何帮助或想法都将非常感谢,因为我确信这只是我做错的简单事情。
Thank you!
谢谢你!
Hefin
Hefin
1 个解决方案
#1
5
There's a much easier way to go about this - install rpy2
from Christoph Gohlke's Python Extension Packages for Windows repository here. Download the rpy2‑2.5.5‑cp34‑none‑win_amd64.whl
file (the current version at the time of this writing), change to the download folder on the command line, and run
有一种更简单的方法来实现这一点——在这里为Windows存储库安装Christoph Gohlke的Python扩展包rpy2。下载rpy2 2.5.5——cp34 - - win_amd64。whl文件(撰写本文时的当前版本),切换到命令行上的下载文件夹,然后运行。
pip install rpy2‑2.5.5‑cp34‑none‑win_amd64.whl
pip
is already included in Python 3.4, and should be used instead of easy_install
when installing new modules, as easy_install
is deprecated.
Python 3.4中已经包含pip,在安装新模块时应该使用pip而不是easy_install,因为easy_install是不赞成使用的。
#1
5
There's a much easier way to go about this - install rpy2
from Christoph Gohlke's Python Extension Packages for Windows repository here. Download the rpy2‑2.5.5‑cp34‑none‑win_amd64.whl
file (the current version at the time of this writing), change to the download folder on the command line, and run
有一种更简单的方法来实现这一点——在这里为Windows存储库安装Christoph Gohlke的Python扩展包rpy2。下载rpy2 2.5.5——cp34 - - win_amd64。whl文件(撰写本文时的当前版本),切换到命令行上的下载文件夹,然后运行。
pip install rpy2‑2.5.5‑cp34‑none‑win_amd64.whl
pip
is already included in Python 3.4, and should be used instead of easy_install
when installing new modules, as easy_install
is deprecated.
Python 3.4中已经包含pip,在安装新模块时应该使用pip而不是easy_install,因为easy_install是不赞成使用的。