Score:1

Trying to install rpy2 results in "ERROR: Command errored out with exit status 1"

cg flag
Ziv

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?

David avatar
cn flag
What version of Ubuntu are you running in WSL?
Ziv avatar
cg flag
Ziv
I think it is Ubuntu 20.04.5 LTS. I got it from the printout of the command `lsb_release -a`.
David avatar
cn flag
In 20.04 LTS, the python included in the base system is Python 3.8. Does the app you are trying to use need this or is it trying to use python 2
Ziv avatar
cg flag
Ziv
Actually it's python 3.9. Could that be a problem?
David avatar
cn flag
You changed the default version of python?
Ziv avatar
cg flag
Ziv
I updated python on my computer to 3.9 a while ago. I'm trying to run a script that was written and run on Linux in another computer.
David avatar
cn flag
Changing the default version of python kills many of the apps that are part of the OS. Ubuntu depends on the default version of python it shipped with. This and the info about mixing Windows and Ubuntu apps may both or either one be the issue. I lean towards messing with python is the issue.
Score:0
vn flag

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.

David avatar
cn flag
He just said he changed the default version of python. Not good.
NotTheDr01ds avatar
vn flag
@David I read that, but I'm assuming that was the *Windows* Python - Maybe thinking that calling `pip` from inside Ubuntu is using that. Doubtful that the Ubuntu system version of Python was replaced or changed. Also note that the error log shown references `~/.local/lib/python3.8/...`. So let's see.
NotTheDr01ds avatar
vn flag
@David Also a possibility that the `pip` was aliased or symlinked to the Windows `pip.exe`? Not sure yet.
David avatar
cn flag
I think we can agree it is complex
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.