%load_ext rpy2.ipython在iPython中有效,但在iPython Notebook中无效

时间:2016-01-21 08:59:45

标签: ipython ipython-notebook rpy2

我有一个问题是让rpy2在iPython笔记本中运行。 如果我加载

%load_ext rpy2.ipython

在iPython 4.0.3中一切都很好。但如果我在iPython笔记本中做同样的事情,我会得到:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-a69f80d0128e> in <module>()
----> 1 get_ipython().magic('load_ext rpy2.ipython')

C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
   2334         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2335         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2336         return self.run_line_magic(magic_name, magic_arg_s)
   2337 
   2338     #-------------------------------------------------------------------------

C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
   2255                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2256             with self.builtin_trap:
-> 2257                 result = fn(*args,**kwargs)
   2258             return result
   2259 

<decorator-gen-65> in load_ext(self, module_str)

C:\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

C:\Anaconda3\lib\site-packages\IPython\core\magics\extension.py in load_ext(self, module_str)
     64         if not module_str:
     65             raise UsageError('Missing module name.')
---> 66         res = self.shell.extension_manager.load_extension(module_str)
     67 
     68         if res == 'already loaded':

C:\Anaconda3\lib\site-packages\IPython\core\extensions.py in load_extension(self, module_str)
     82             if module_str not in sys.modules:
     83                 with prepended_to_syspath(self.ipython_extension_dir):
---> 84                     __import__(module_str)
     85             mod = sys.modules[module_str]
     86             if self._call_load_ipython_extension(mod):

C:\Anaconda3\lib\site-packages\rpy2\ipython\__init__.py in <module>()
----> 1 from .rmagic import load_ipython_extension

C:\Anaconda3\lib\site-packages\rpy2\ipython\rmagic.py in <module>()
     50 # numpy and rpy2 imports
     51 
---> 52 import rpy2.rinterface as ri
     53 import rpy2.robjects as ro
     54 import rpy2.robjects.packages as rpacks

C:\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py in <module>()
     72         if not os.path.exists(Rlib):
     73             continue
---> 74         ctypes.CDLL(Rlib)
     75         _win_ok = True
     76         break

C:\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    345 
    346         if handle is None:
--> 347             self._handle = _dlopen(self._name, mode)
    348         else:
    349             self._handle = handle

FileNotFoundError: [WinError 161] Der angegebene Pfadname ist ungültig

有没有办法让两个都跑?由于rpy2在iPython中正常运行,我猜安装设备是正确的。 谢谢, MARV

1 个答案:

答案 0 :(得分:0)

调用ipython的环境与调用笔记本的环境之间可能存在更多差异:尝试R共享库时发生错误Der angegebene Pfadname ist ungültig

您需要告诉我们更多关于如何启动ipython或笔记本电脑的信息。

话虽如此,你还应该注意rpy2在Linux或OS X上的效果可能更好。如果ipython笔记本是你的主要兴趣,那么通过Docker容器运行可能是一个很好的解决方案。