0

There are a lot of other questions like mine but they're quite outdated so I think a new updated guide would be helpful for everyone trying to install rpy2 in Python.
In my case, I'm trying to work with the package pymer4 but i couldn't manage to correctly import it.
I found out that the error lies in rpy2.robjects so I decided to follow this answer to create a clean environment

Steps

  1. I created a new conda environment

    conda create -n rpy2_env r-essentials<4.2 r-base<4.2 python=3.7

I set the version to <4.2 because I read online this problem can be caused by a wrong r version. Anyway neither 4.2 nor 4.1 worked for me.

  1. I installed the pymer4 package (and its dependecies, including rpy2)
    conda install -c ejolly -c conda-forge pymer4

  2. I downgraded rpy2 to 3.4.5 (see related question below, I also tried without downgrading)
    conda install rpy2=3.4.5

  3. When i try to import pymer4 or rpy2.robjects the following error shows up

    R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) : 3 arguments passed to .Internal(gettext) which requires 2

In the terminal the logs showed no error during download and installation.
If you need more info about my system or anything else, comment and I will update the question.
I am really stuck at this point, I think i tried everything I could. I would really appreciate if someone could enlighten me.

Similar Questions
Import rpy2 : unable to determine R library path
Rpy2 can't find my R libraries on install
R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) : 3 arguments passed to .Internal(gettext) which requires 2

StackyGuy
  • 37
  • 7

1 Answers1

1

I think I found the solution.
The problem is with conda and rpy2, apparently rpy2 installed with conda is outdated.
You can install correctly rpy2 on a new environment (venv or conda env) using pip. I did it and so far it's working perfectly.

StackyGuy
  • 37
  • 7
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – user11717481 Nov 14 '22 at 10:14
  • 1
    Since the stack police won't let me edit the answer I'll just add a comment here. For everyone who is trying to install rpy2: do not use conda package manager and just use the pip package manager and everything will work fine. The correct way to install rpy thus is `pip install rpy2`. Be sure not to use `conda install` for other packages in the same environment where you installed rpy2 with pip to avoid possible conflicts. – StackyGuy Nov 16 '22 at 13:36