加载 rpy2 时出现 Jupyter OSError 0x7e

H. *_*ert 5 rpy2 jupyter-notebook

我在 Windows 10 上,我有一个新安装的 Anaconda Python 3.7 64 位,出于某些原因,我想在我的 D: 驱动器上运行我的 jupiter 笔记本。然后我打开我的 jupyter 命令,并在启动 jupyter notebook 之前将自己放在 D: 中。当我想加载 rpy2 时,我遇到了这个问题:


%load_ext rpy2.ipython
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-52-fb23c6edefe4> in <module>
----> 1 get_ipython().run_line_magic('load_ext', 'rpy2.ipython')

~\anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2315                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2316             with self.builtin_trap:
-> 2317                 result = fn(*args, **kwargs)
   2318             return result
   2319 

<C:\Users\Romain\anaconda3\lib\site-packages\decorator.py:decorator-gen-65> in load_ext(self, module_str)

~\anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~\anaconda3\lib\site-packages\IPython\core\magics\extension.py in load_ext(self, module_str)
     31         if not module_str:
     32             raise UsageError('Missing module name.')
---> 33         res = self.shell.extension_manager.load_extension(module_str)
     34 
     35         if res == 'already loaded':

~\anaconda3\lib\site-packages\IPython\core\extensions.py in load_extension(self, module_str)
     78             if module_str not in sys.modules:
     79                 with prepended_to_syspath(self.ipython_extension_dir):
---> 80                     mod = import_module(module_str)
     81                     if mod.__file__.startswith(self.ipython_extension_dir):
     82                         print(("Loading extensions from {dir} is deprecated. "

~\anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

~\anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

~\anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

~\anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

~\anaconda3\lib\importlib\_bootstrap.py in _load_unlocked(spec)

~\anaconda3\lib\importlib\_bootstrap_external.py in exec_module(self, module)

~\anaconda3\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~\anaconda3\lib\site-packages\rpy2\ipython\__init__.py in <module>
----> 1 from . import rmagic
      2 
      3 load_ipython_extension = rmagic.load_ipython_extension

~\anaconda3\lib\site-packages\rpy2\ipython\rmagic.py in <module>
     53 # numpy and rpy2 imports
     54 
---> 55 import rpy2.rinterface as ri
     56 import rpy2.rinterface_lib.callbacks
     57 import rpy2.robjects as ro

~\anaconda3\lib\site-packages\rpy2\rinterface.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

~\anaconda3\lib\site-packages\rpy2\rinterface_lib\openrlib.py in <module>
     42     rlib = _rinterface_cffi.lib
     43 else:
---> 44     rlib = _dlopen_rlib(R_HOME)
     45 
     46 

~\anaconda3\lib\site-packages\rpy2\rinterface_lib\openrlib.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 Files\R\R-3.6.1\bin\x64\R.dll': error 0x7e
Run Code Online (Sandbox Code Playgroud)

我肯定知道这是因为我的笔记本在不同的硬盘上运行。我试图将 R 目录添加到我的 Windows 路径中,但它没有改变任何东西。

我怎样才能在我的驱动器 D: 上运行我的笔记本而不会出现这些问题?

谢谢你,