Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue: rpy2 >= 3.6 requires sh and make on Windows #1188

@hollenstein

Description

@hollenstein

First of all, many thanks for developing and maintaining this very useful library

Short description of the issue:
It seems that starting from rpy2 >= 3.6, the library depends on Unix tools sh.exe and make being available on Windows. I believe this wasn't required in prior versions like 3.5.17. This change increases setup complexity on Windows systems.

To Reproduce

  • Install Python 3.13 on a Windows machine with R 4.4.2 installed and the "R_HOME" environment variable set but doesn't have sh and make installed.
  • Run pip install rpy2==3.6.1
  • Run the following code in python import rpy2.robjects

Expected behavior
On Windows, the only requirements for rpy2 should ideally be:

  • A valid R installation
  • The "R_HOME" environment variable correctly set

I have to admit that I don't really understand how rpy2 is built and installed locally. I believe the R CMD config --ldflags is required to retrieve the "R_PATH" during building, but I am not sure. Would there be a possibility to have a fallback and alternative mechanism on Windows, which doesn't require calling R CMD config --ldflags?

I would be happy to help with testing alternative implementations on Windows, but coming up with a solution on my own seems beyond my abilities.

Long version:
After installing rpy2 == 3.6.1 on a Windows machine the following error occurs when calling import rpy2.robjects as robjects in Pyhton.

In [3]: import rpy2.robjects as robjects
'sh' is not recognized as an internal or external command,
operable program or batch file.
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[3], line 1
----> 1 import rpy2.robjects as robjects

...


CalledProcessError: Command '('C:\\Users\\user.name\\R\\R-4.4.2\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 1.

Seems like rpy2 is now using R CMD config --ldflags (not sure if it was actually using it before or not, but at least it was not required), which doesn't work because by default there is no sh.exe on Windows.

So I've added the the git binary folder to the windows PATH, which contains sh.exe. Then I've got the following error, because windows doesn't have the make command.

C:\Users\user.name\python_venv>"C:\Users\user.name\R\R-4.4.2\bin\x64\R" CMD config --ldflags
C:\Users\user.name\R\R-4.4.2/bin/config.sh: line 187: make: command not found
C:\Users\user.name\R\R-4.4.2/bin/config.sh: line 188: make: command not found
C:\Users\user.name\R\R-4.4.2/bin/config.sh: line 189: make: command not found
C:\Users\user.name\R\R-4.4.2/bin/config.sh: line 190: make: command not found
C:\Users\user.name\R\R-4.4.2/bin/config.sh: line 191: make: command not found
R was not built as a library

I've solved this by installing rtools 4.4, now calling "C:\Users\user.name\R\R-4.4.2\bin\x64\R" CMD config --ldflags seems to work. And also rpy2 seems to work. However, I still get a warning when calling import rpy2.robjects as robjects in Python, but this is likely an unrelated issue.

Error importing in API mode: ImportError('On Windows, cffi mode "ANY" is only "ABI".')
Trying to import in ABI mode.
C:\Users\user.name\python_venv\rpy2-test\Lib\site-packages\rpy2\rinterface\__init__.py:1211: UserWarning: Environment variable "PATH" redefined by R and overriding existing variable.

Current: "C:\Users\user.name\python_venv\rpy2-test\Scripts;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Thermo\Foundation\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\Thermo\Foundation\;C:\Program Files\Git\cmd;C:\Program Files\Git\bin;C:\Users\user.name\.local\bin;C:\Users\user.name\AppData\Local\Microsoft\WindowsApps;C:\Users\user.name\.dotnet\tools;C:\Users\user.name\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user.name\AppData\Local\GitHubDesktop\bin;;C:\Users\user.name\R\R-4.4.2\bin\x64",

R: "c:/rtools44/x86_64-w64-mingw32.static.posix/bin;c:/rtools44/usr/bin;C:\Users\user.name\python_venv\rpy2-test\Scripts;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Thermo\Foundation\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\Thermo\Foundation\;C:\Program Files\Git\cmd;C:\Program Files\Git\bin;C:\Users\user.name\.local\bin;C:\Users\user.name\AppData\Local\Microsoft\WindowsApps;C:\Users\user.name\.dotnet\tools;C:\Users\user.name\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user.name\AppData\Local\GitHubDesktop\bin;;C:\Users\user.name\R\R-4.4.2\bin\x64"
  
  warnings.warn(
C:\Users\user.name\python_venv\rpy2-test\Lib\site-packages\rpy2\rinterface\__init__.py:1211: UserWarning: Environment variable "R_HOME" redefined by R and overriding existing variable. Current: "C:\Users\user.name\R\R-4.4.2", R: "C:/Users/user.name/R/R-4.4.2"
  
  warnings.warn(
C:\Users\user.name\python_venv\rpy2-test\Lib\site-packages\rpy2\rinterface\__init__.py:1211: UserWarning: Environment variable "PATH" redefined by R and overriding existing variable. Current: "c:/rtools44/x86_64-w64-mingw32.static.posix/bin;c:/rtools44/usr/bin;C:\Users\user.name\python_venv\rpy2-test\Scripts;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Thermo\Foundation\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\Thermo\Foundation\;C:\Program Files\Git\cmd;C:\Program Files\Git\bin;C:\Users\user.name\.local\bin;C:\Users\user.name\AppData\Local\Microsoft\WindowsApps;C:\Users\user.name\.dotnet\tools;C:\Users\user.name\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user.name\AppData\Local\GitHubDesktop\bin;;C:\Users\user.name\R\R-4.4.2\bin\x64", R: "c:/rtools44/x86_64-w64-mingw32.static.posix/bin;c:/rtools44/usr/bin;c:/rtools44/x86_64-w64-mingw32.static.posix/bin;c:/rtools44/usr/bin;c:/rtools44/x86_64-w64-mingw32.static.posix/bin;c:/rtools44/usr/bin;C:\Users\user.name\python_venv\rpy2-test\Scripts;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Thermo\Foundation\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\Thermo\Foundation\;C:\Program Files\Git\cmd;C:\Program Files\Git\bin;C:\Users\user.name\.local\bin;C:\Users\user.name\AppData\Local\Microsoft\WindowsApps;C:\Users\user.name\.dotnet\tools;C:\Users\user.name\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user.name\AppData\Local\GitHubDesktop\bin;;C:\Users\user.name\R\R-4.4.2\bin\x64"
  warnings.warn(

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions