Skip to content

M1 mac MemoryError calling rpy2 in jupyter notebook #790

@selmling

Description

@selmling

Describe the issue or bug

Calling %load_ext rpy2.ipython in a jupyter notebook on a M1 mac results in the following error:

MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks

Expected behavior is to run without an error message.

Error message in full:

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

~/miniforge3/lib/python3.9/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2342                 kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2343             with self.builtin_trap:
-> 2344                 result = fn(*args, **kwargs)
   2345             return result
   2346 

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

~/miniforge3/lib/python3.9/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):

~/miniforge3/lib/python3.9/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':

~/miniforge3/lib/python3.9/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. "

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

~/miniforge3/lib/python3.9/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/miniforge3/lib/python3.9/importlib/_bootstrap.py in _find_and_load(name, import_)

~/miniforge3/lib/python3.9/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

~/miniforge3/lib/python3.9/importlib/_bootstrap.py in _load_unlocked(spec)

~/miniforge3/lib/python3.9/importlib/_bootstrap_external.py in exec_module(self, module)

~/miniforge3/lib/python3.9/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/miniforge3/lib/python3.9/site-packages/rpy2/ipython/__init__.py in <module>
----> 1 from . import rmagic
      2 
      3 load_ipython_extension = rmagic.load_ipython_extension

~/miniforge3/lib/python3.9/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

~/miniforge3/lib/python3.9/site-packages/rpy2/rinterface.py in <module>
     11 from typing import Union
     12 from rpy2.rinterface_lib import openrlib
---> 13 import rpy2.rinterface_lib._rinterface_capi as _rinterface
     14 import rpy2.rinterface_lib.embedded as embedded
     15 import rpy2.rinterface_lib.conversion as conversion

~/miniforge3/lib/python3.9/site-packages/rpy2/rinterface_lib/_rinterface_capi.py in <module>
     10 from rpy2.rinterface_lib import openrlib
     11 from rpy2.rinterface_lib import conversion
---> 12 from rpy2.rinterface_lib import embedded
     13 from rpy2.rinterface_lib import memorymanagement
     14 

~/miniforge3/lib/python3.9/site-packages/rpy2/rinterface_lib/embedded.py in <module>
      5 import warnings
      6 from rpy2.rinterface_lib import openrlib
----> 7 from rpy2.rinterface_lib import callbacks
      8 
      9 ffi = openrlib.ffi

~/miniforge3/lib/python3.9/site-packages/rpy2/rinterface_lib/callbacks.py in <module>
     37 @ffi_proxy.callback(ffi_proxy._consoleflush_def,
     38                     openrlib._rinterface_cffi)
---> 39 def _consoleflush() -> None:
     40     try:
     41         consoleflush()

~/miniforge3/lib/python3.9/site-packages/rpy2/rinterface_lib/ffi_proxy.py in decorator(func)
     42     def decorator(func):
     43         if get_ffi_mode(_rinterface_cffi) == InterfaceType.ABI:
---> 44             res = _rinterface_cffi.ffi.callback(definition.callback_def)(func)
     45         elif get_ffi_mode(_rinterface_cffi) == InterfaceType.API:
     46             res = _rinterface_cffi.ffi.def_extern()(func)

MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks

The installation of rpy2 passes with pip.

Related issue here

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions