user1568416
user1568416

Reputation: 71

Trouble importing from rpy2.robjects

I'm relatively new to Python (Anaconda 3.6.0, 64-bit on win10) and I'm having trouble getting it to play nice with R (3.3.2).

I installed RPy2 (ver 2.8.5) using conda install and then tried to get things working in python:

import rpy2
from rpy2 import robjects

But I get a perplexing and somewhat unhelpful error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\mdmms\Anaconda3\lib\site-packages\rpy2\robjects\__init__.py", line 16, in <module>
    import rpy2.rinterface as rinterface
  File "C:\Users\mdmms\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 87, in <module>
    _load_r_dll(R_HOME)
  File "C:\Users\mdmms\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 64, in _load_r_dll
    ctypes.CDLL(r_dll)
  File "C:\Users\mdmms\Anaconda3\lib\ctypes\__init__.py", line 344, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

I have looked at similar threads but to no avail. Please help if you can, but please be nice, I'm new on here.

Upvotes: 1

Views: 1209

Answers (1)

suku
suku

Reputation: 10929

Here is how I managed to solve it from mingwandroid in this discussion

  1. Open the path variable list (Open Advanced System Settings and then Environment Variables and then PATH under user variables)
  2. Remove all the paths assigned to anaconda
  3. Open anaconda prompt from the start menu
  4. Then add the following PATH variables to the path

    C:\Anaconda; C:\Anaconda\Library\mingw-w64\bin; C:\Anaconda\Library\usr\bin; C:\Anaconda\Library\bin; C:\Anaconda\Scripts;

  5. Now close the ide if it is open and then restart the ide

    Now the code should work.

P.S.: I also had menuist updated as suggested in the discussion. I am not sure whether that is necessary.

Upvotes: 1

Related Questions