Search code examples
pythonrrpy2loadlibrary

LoadLibrary failure with rpy2


After upgrading R and rpy2 I found a LoadLibrary failure problem with rpy2 when importing the R package stats. After running the following code:

import rpy2.robjects as robjects
from rpy2.objects.packages import importr
rstats = importr('stats')

I receive the error message

RRuntimeError: Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Program Files/R/R-3.4.3/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module cannot be found.

Other modules are imported correctly, unless they import stats themselves. I have tried to reinstall R and rpy2 to no avail. A similar issue reported a problem with a path in the .Renviron file. This file does not exist in my computer.

My R_HOME is C:\Program Files\R\R-3.4.3 and my R_USER is C:\Users\user.name.

Could you help me find what is the problem and how to solve it?


Solution

  • I solved the problem by adding C:\Program Files\R\R-3.4.3\bin\x64 to the path. I think that this address was deleted from the path when I uninstalled the previous R version. And you need to install the address manually to the path after installing the new version, according to the R for Windows FAQ.