使用easy_install在Python中安装rpy2模块时出错

jutyujz0  于 2023-04-27  发布在  Python
关注(0)|答案(3)|浏览(139)

我一直在尝试安装rpy 2模块,这样我就可以在Python脚本中使用R函数,但在遵循这些页面的建议后,我收到了一个错误:

1)Tried to guess R's HOME but no R command in the PATH. OsX 10.6
2)http://rpy.sourceforge.net/rpy2/doc-dev/html/overview.html

到目前为止我所做的:

**1)**修改了我的路径环境变量,将“C:\Program Files\R\R-3.1.0\bin\x64;”
**2)**创建一个新的环境变量“R_HOME”,并将其值设置为“C:\Program Files\R\R-3.1.0”
**3)**创建了一个名为“R_USER”的新环境变量,并将其值设置为“Hefin”(我的Windows用户名)

然后在命令提示符下键入:

easy_install rpy2

据我所知,easy_install是正确安装的。
我得到的输出是:

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>

对不起,这太冗长了!如果我调用python并尝试导入rpy模块,我会得到:

>>> import python
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'python'
>>>

恐怕我是Python的新手,我不知道我做错了什么。我已经搜索了以前的论坛帖子,但似乎没有一个有这个问题。我使用的是64位机器,Windows 7,Python3.4和R3.1.0。
任何帮助或想法将不胜感激,因为我相信这只是一些简单的我做错了。
谢谢大家!
赫芬

tktrz96b

tktrz96b1#

有一种更简单的方法可以做到这一点-从Christoph Gohlke的Python Extension Packages for Windows存储库中安装rpy2

pip install rpy2‑2.5.5‑cp34‑none‑win_amd64.whl

pip已经包含在Python 3.4中,在安装新模块时应该使用它来代替easy_install,因为easy_install已被弃用。

nbnkbykc

nbnkbykc2#

在windows上安装rpy2是直接使用conda

conda install rpy2
uplii1fm

uplii1fm3#

pip install rpy2,last version 3.5.11 get error on my system:Windows 10、Python 3.9.13、R 4.2.2:

Collecting rpy2
  Using cached rpy2-3.5.11.tar.gz (216 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error

  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\mymachine\Anaconda3\python.exe' 'C:\Users\mymachine\Anaconda3\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' get_requires_for_build_wheel 'C:\Users\DPP105~1\AppData\Local\Temp\tmpcbljn8c_'
       cwd: C:\Users\mymachine\AppData\Local\Temp\pip-install-wkxzg2xw\rpy2_1c88b3b8df374808a01f7123d55b08c4
  Complete output (28 lines):
  Traceback (most recent call last):
    File "C:\Users\mymachine\Anaconda3\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 363, in <module>
      main()
    File "C:\Users\mymachine\Anaconda3\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Users\mymachine\Anaconda3\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 130, in get_requires_for_build_wheel
      return hook(config_settings)
    File "C:\Users\mymachine\AppData\Local\Temp\pip-build-env-vk_sr3qd\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "C:\Users\mymachine\AppData\Local\Temp\pip-build-env-vk_sr3qd\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
      self.run_setup()
    File "C:\Users\mymachine\AppData\Local\Temp\pip-build-env-vk_sr3qd\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
      exec(code, locals())
    File "<string>", line 124, in <module>
    File "<string>", line 110, in get_r_c_extension_status
    File "./rpy2/situation.py", line 295, in get_r_flags
      _get_r_cmd_config(r_home, flags,
    File "./rpy2/situation.py", line 255, in _get_r_cmd_config
      output = subprocess.check_output(
    File "C:\Users\mymachine\Anaconda3\lib\subprocess.py", line 424, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "C:\Users\mymachine\Anaconda3\lib\subprocess.py", line 505, in run
      with Popen(*popenargs, **kwargs) as process:
    File "C:\Users\mymachine\Anaconda3\lib\subprocess.py", line 951, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File "C:\Users\mymachine\Anaconda3\lib\subprocess.py", line 1420, in _execute_child
      hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  FileNotFoundError: [WinError 2] Impossibile trovare il file specificato

相关问题