Rpy2 import not working

I get an error when trying to import rpy2. Here is the code and the error.

>>> import pandas.rpy.common
Traceback (most recent call last):  

File "C:\PF\WinPython-64bit-3.3.3.3\python-3.3.3.amd64\lib\site-packages\IPython\core\interactiveshell.py", line 2828, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

File "<ipython-input-148-c258a0f70d44>", line 1, in <module>
import pandas.rpy.common

File "C:\PF\WinPython-64bit-3.3.3.3\python-3.3.3.amd64\lib\site-packages\pandas\rpy\common.py", line 14, in <module>
from rpy2.robjects.packages import importr

ImportError: No module named 'rpy2'

What could be the problem? I am using python version 3.3.3 and pandas version 0.13.1

EDIT

I tried installing rpy2 separately.

  • Direct use python setup.py installgave me an error that osdoes not have a module popen3.

  • Directly installing exe (rpy2-2.3.9.win32-py3.3.exe) from the Christoph Gohlke website http://www.lfd.uci.edu/~gohlke/pythonlibs/ works fine. But if I try to do import pandas.rpy.common as com, then I get the following error (problem loading the DLL in from rpy2.rinterface._rinterface import *:

    Traceback (most recent call last):
      File "C:\PF\WinPython-64bit-3.3.3.3\python-3.3.3.amd64\lib\site-packages\IPython\core\interactiveshell.py", line 2828, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
    
      File "<ipython-input-10-63ebebefea80>", line 1, in <module>
    import pandas.rpy.common as com
    
      File "C:\PF\WinPython-64bit-3.3.3.3\python-3.3.3.amd64\lib\site-    packages\pandas\rpy\common.py", line 14, in <module>
    
    from rpy2.robjects.packages import importr
    
      File "C:\PF\WinPython-64bit-3.3.3.3\python-3.3.3.amd64\lib\site-packages\rpy2\robjects\__init__.py", line 15, in <module>
    
        import rpy2.rinterface as rinterface
      File "C:\PF\WinPython-64bit-3.3.3.3\python-3.3.3.amd64\lib\site-packages\rpy2\rinterface\__init__.py", line 103, in <module>
    
        from rpy2.rinterface._rinterface import *
    ImportError: DLL load failed: %1 is not a valid Win32 application.
    

EDIT

In the end, I decided. It seems that adding environment variables R_HOME and R_USER led to the trick.

+3
source share
6

RPy2 - Pandas ( ), . pip install rpy2, Python .

+3

, , pandas rpy2 , . , :

from rpy2.robjects import r, pandas2ri

pandas2ri.activate()

, pandas R, pandas2ri.py2ri() pandas2ri.ri2py(), R pandas. https://pandas.pydata.org/pandas-docs/stable/r_interface.html.

+1

pandas rpy2. , rpy2 . rpy2, :

In [1]: import pandas.rpy.common
(...)
ImportError: No module named rpy2.robjects.packages


In [2]: import rpy2
(...)
ImportError: No module named rpy2

pip:

$ pip install rpy2

In [1]: import pandas.rpy.common

! import rpy2 , import pandas.rpy.common , .

0

conda. , .

source activate [environment Name]
conda install -c r rpy2=2.8.5
0

. rpy2 anaconda python (3.6.3). ,

* python3 -m conda install rpy2
0

, Anaconda Prompt :

conda install -m rpy2

After that, I had to move the rpy2 directory from rpy2-2.9.0-py3.6-win32.egg (the folder that was installed) because it did not recognize it after installation .. and only moved the rpy2 folder to the following path:

C: \ Users \ .. Anaconda3 \ Lib \ site packages (where all packages are called from)

This issue is resolved for me.

0
source

All Articles