1

I'm trying to install rpy2 in Ubuntu for Windows with the command pip install rpy2, which yields the following error message:

ERROR: Command errored out with exit status 1:
 command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-isr_d1d8/rpy2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-isr_d1d8/rpy2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-isr_d1d8/rpy2/pip-egg-info
     cwd: /tmp/pip-install-isr_d1d8/rpy2/
Complete output (9 lines):
Unable to determine R home: [Errno 2] No such file or directory: 'R'
/home/ziv/.local/lib/python3.8/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.23ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
/home/ziv/.local/lib/python3.8/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.1.36ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
/home/ziv/.local/lib/python3.8/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
  warnings.warn(
Unable to determine R home: [Errno 2] No such file or directory: 'R'
Error: rpy2 in API mode cannot be built without R in the PATH or R_HOME defined. Correct this or force ABI mode-only by defining the environment variable RPY2_CFFI_MODE=ABI
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I tried following the instructions in the message and used the command RPY2_CFFI_MODE=ABI. I couldn't find where the log files that are referred to in the above message are. I also added R to the PATH with the command export PATH=$PATH:/mnt/c/Program\ Files/R/R-4.2.1/bin/x64/R.exe, as well as setting an R_HOME variable: R_HOME=/mnt/c/Program\ Files/R/R-4.2.1/bin/x64/. I still got the error message after trying these solutions.

Any ideas?

Ziv
  • 11

1 Answers1

0

Just a quick aside that I like this question. It's a good question. Some questions are "good" because they are problems that will impact many people, but that's probably not the case here. Some are "good" because they are thought-provoking or hard problems to solve -- Again, not-so-much here. This one is good because it includes what you've done to try to solve the problem (the Search, and research ... rule). Only with this information is the problem apparent!

I also added R to the PATH with the command export PATH=$PATH:/mnt/c/Program\ Files/R/R-4.2.1/bin/x64/R.exe, as well as setting an R_HOME variable: R_HOME=/mnt/c/Program\ Files/R/R-4.2.1/bin/x64/

So this indicates that you have installed the Windows version of R, but you are trying to install this package in Ubuntu (Linux/WSL) using the Linux pip command. Unfortunately this just isn't going to work. You'll need to either be using:

  • Windows Python with Windows R with Windows pip
  • Or the Linux versions of all of the above

The Linux version of pip just isn't going to look for R.exe, because the Linux version is just R. Linux doesn't really have the concept of file extensions.

Even if you were able to tell the pip installer somehow that it should look for R.exe, you'd still run into multiple other issues due to:

  • Linux paths using the / separator vs. Windows paths using \.
  • (Potentially) Linux-native R modules not running inside a Windows-native Python process.
  • Differences in expected locations of configuration files.
  • And probably a few others

If you want to develop using the Windows version of R, you'll need to install the Windows version of Python/Pip and work from PowerShell or CMD.

However, if you want to develop using the Linux/Ubuntu versions through WSL, then you'll need to use the Linux version of R. This is an area where I don't have a lot of expertise myself, but my understanding is that most people use the CRAN PPA to obtain the latest R version in Ubuntu. See this Ask Ubuntu question (old, but I believe still relevant -- Also points to a Stack Overflow question) or this Digital Ocean guide for details.

Note that, since R is heavily dependent on a GUI, you'll need to either be running WSL under Windows 11 with WSLg support, or use one of the workarounds on Windows 10. See this and this (much more detailed) post for more information.

NotTheDr01ds
  • 22,082