1

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:

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


What I've done so far:

1) Edited my path environment variable to include "C:\Program Files\R\R-3.1.0\bin\x64;"

2) Created a new environment variable called "R_HOME" and set its value to "C:\Program Files\R\R-3.1.0"

3) Created a new environment variable called "R_USER" and set its value to "Hefin" (my windows username)

Then in my command prompt I type:

easy_install rpy2

As far as I'm aware, easy_install is setup and installed correctly.

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:

>>> 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.

Any help or thoughts would be much appreciated as I'm sure it's just something simple I'm doing wrong.

Thank you!

Hefin

Community
  • 1
  • 1
Hefin
  • 77
  • 1
  • 2
  • 9

3 Answers3

10

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

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.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • 3
    Thank you for your answer! I didn't realise easy_install was old hat. so I just did what you suggested and this is what I get: 'C:\Users\Hefin\Downloads>pip install rpy2-2.5.5-cp34-none-win_amd64.whl' 'rpy2-2.5.5-cp34-none-win_amd64.whl is not a supported wheel on this platform. Storing debug log for failure in C:\Users\Hefin\pip\pip.log' – Hefin Feb 08 '15 at 10:47
  • Did you install 32- or 64-bit Python? Are you using the python.org version, or some other distribution like Anaconda or Python(x,y)? At the command line, just run `python` and report what the top line or two is. – MattDMo Feb 08 '15 at 19:50
  • Also, please scan through the `pip.log` file and add its contents to your question, or if it's too big to a site like pastebin. – MattDMo Feb 08 '15 at 19:52
  • So the version of Python (from python.org) is 3.4.2. pip.log is http://pastebin.com/5qsrdicS – Hefin Feb 10 '15 at 09:53
  • @Hefin try downloading and installing the `cp34‑none‑win32.whl` and see if that does the trick. – MattDMo Feb 12 '15 at 17:43
  • Thanks @MattDMo, this actually installs rpy2 (woo hoo!) but when I try `import rpy2.robjects as objects` I get the error: http://pastebin.com/MCfW9bib . I have also tried the 32 and 64-bit versions for earlier versions of python, but I get the "not a supported wheel on this platform" error. – Hefin Feb 16 '15 at 17:15
  • Thank you for your answer, but after installing pywin32 I still get the same error message. I can import rpy2, but I get an error with `import rpy2.robjects as objects` . – Hefin Feb 17 '15 at 15:41
  • I am getting a similar error on Heroku and I can't figure how to apply this on Heroku. In my case when Heroku get to the line for rpy2 in my requirements file, it goes to the following link for downloading rpy2 and then produces the error. "https://files.pythonhosted.org/packages/02/d1/074ffbbe7b4bf74c60b75d74c8e67a1e4515b0d85f85cd6540e39610754a/rpy2-2.9.5.tar.gz" – Sher Afghan May 23 '19 at 06:22
5

Installing rpy2 on windows is straight forward using conda

conda install rpy2
Nobel
  • 1,485
  • 1
  • 16
  • 19
0

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