Installing rpy2 on windows
The output contains the error:
'sh' is not recognized as an internal or external command
but I thought it was only a warning (as there was output coming after it).
sh (shell) is Nix specific and (naturally) doesn't exist on Win. However, if you install a port for Win, or an Lnx env emulator (like Cygwin), it might work.
Here's what [ReadTheDocs.rpy2]: Installation (which has "Compiling on Linux" and "Compiling on OS X" sections, but nothing about Win, although it mentions that it should compile successfully) states:
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
Update #0
Adding steps that @pyguy took (from comment), in order to successfully install rpy2:
- Download rpy2‑2.9.3‑cp35‑cp35m‑win_amd64.whl (or any newer version that might have been added in the meantime) from [UCI.LFD]: Unofficial Windows Binaries for Python Extension Packages (for 32bit, download the *win32.whl)
- Open a cmd window (as Administrator) in the .whl's download dir
- Set R_USER env var to current username:
set R_USER=%USERNAME%
python -m pip install rpy2‑2.9.3‑cp35‑cp35m‑win_amd64.whl
(Python's (binary) dir must be in %PATH%, or specify the full path)
Error installing RPy2-2.3.8 on Windows 7, Python 3.3
RPy does not support Python 3.x. You have to use 2.5 <= Python < 3.0. See official documentation for details.
Installing rpy2
If you're desperate, you could install WinPython (for windows users) which has a lot of Packages already installed and ready to use, including rpy2, sometimes installing packages on windows can be stressful.
Or if you really want to make it work that way, maybe you could check if that package was installed in the Downloads folder and move it to the folder corresponding to python libraries
Rpy2 on windows
OLD ANSWER
The issue was that I downloaded the wrong wheel. cp37
means CPython 3.7
and I have python 3.6
on my system. I downloaded rpy2-2.9.5-cp36-cp36m-win_amd64.whl
istead of rpy2-2.9.5-cp37-cp37m-win_amd64.whl
and it worked.
Also as I faced problems with R_USER
and R_HOME
I did the following in my python script:
import os
# see the following 2 lines
os.environ['R_HOME'] = 'C:/Program Files/R/R-3.6.2'
os.environ['R_USER'] = 'C:/Users/96171/AppData/Local/Programs/Python/Python36/Lib/site-packages/rpy2' #path depends on where you installed Python. Mine is the site packages of the regular python installation, it could have been Anaconda
# importing rpy2
import rpy2.robjects as robjects
r = robjects.r
r['source']('sample_r.r')
References: this
UPDATED
To avoid os calls
I was able to achieve the desired behavior by including R_USER
and R_HOME
to the SYSTEM VARIABLE
in ENVIRONMENT VARIABLES
- R_USER:
C:\Users\96171\AppData\Local\Programs\Python\Python36\Lib\site-packages\rpy2 - R_HOME: C:\Program Files\R\R-3.6.2
Related Topics
Get Last N Lines of a File, Similar to Tail
Fetching the Output of a Command Executed Through Os.System() Command
Opening a Python Thread in a New Console Window
Does R Have Function Startswith or Endswith Like Python
Cannot Get Environment Variables in Django Settings File
Writing to Shared Memory in Python Is Very Slow
Check If a Process Is Running Using Python on Linux
Install Scipy with Mkl Through Pip
Cross Platform Numpy.Random.Seed()
How to Crop an Image in Opencv Using Python
Get All Modules/Packages Used by a Python Project
Oserror: [Error 1] Operation Not Permitted
Converting Python Objects for Rpy2
Python Linux Selenium: Chrome Not Reachable
How to Get Each Dependent Command Execution Output Using Paramiko Exec_Command