Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

python - OSError: cannot load library 'C:Program FilesRR-4.0.2inx64R.dll': error 0x7e

I am trying to import the rpy2 library into a Jupyter Notebook but I cannot get past this error.

The PATH 'C:Program FilesRR-4.0.2inx64' has been added.

This is the only version of R installed on my computer. I have completely uninstalled and reinstalled R/Rstudio/Anaconda with no luck.

Here is the full error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-7-098f0d39b3a3> in <module>
----> 1 from rpy2.robjects import pandas2ri

C:Anacondalibsite-packages
py2
objects\__init__.py in <module>
     14 from functools import partial
     15 import types
---> 16 import rpy2.rinterface as rinterface
     17 import rpy2.rlike.container as rlc
     18 

C:Anacondalibsite-packages
py2
interface.py in <module>
      4 import typing
      5 from typing import Union
----> 6 from rpy2.rinterface_lib import openrlib
      7 import rpy2.rinterface_lib._rinterface_capi as _rinterface
      8 import rpy2.rinterface_lib.embedded as embedded

C:Anacondalibsite-packages
py2
interface_libopenrlib.py in <module>
     42     rlib = _rinterface_cffi.lib
     43 else:
---> 44     rlib = _dlopen_rlib(R_HOME)
     45 
     46 

C:Anacondalibsite-packages
py2
interface_libopenrlib.py in _dlopen_rlib(r_home)
     35         raise ValueError('The library path cannot be None.')
     36     else:
---> 37         rlib = ffi.dlopen(lib_path)
     38     return rlib
     39 

OSError: cannot load library 'C:Program FilesRR-4.0.2inx64R.dll': error 0x7e

edit:

Here is the code I run to import rpy2 library:

from rpy2.robjects import r, pandas2ri
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is my working solution:

import os
os.environ["R_HOME"] = r"D:InstallRR-3.6.1"
os.environ["PATH"]   = r"D:InstallRR-3.6.1inx64" + ";" + os.environ["PATH"]
import rpy2
from rpy2.robjects import pandas2ri, packages
pandas2ri.activate()
stats = packages.importr('stats')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...