theislab / anndata2ri

Convert between AnnData and SingleCellExperiment
https://icb-anndata2ri.readthedocs-hosted.com/
GNU General Public License v3.0
124 stars 16 forks source link

Issue on %load_ext rpy2.ipython #145

Closed ScienceComputing closed 9 months ago

ScienceComputing commented 9 months ago

Hi,

in Google colab, the following error pops up: NotImplementedError: Conversion rules for rpy2.robjects appear to be missing. Those rules are in a Python contextvars.ContextVar. This could be caused by multithreading code not passing context to the thread.

Code:

!pip install anndata2ri # Install the latest 1.3.1 version
import anndata2ri
anndata2ri.activate()
%load_ext rpy2.ipython

Error:

<ipython-input-4-9fc1bec6d256>:2: DeprecationWarning: The global conversion available with activate() is deprecated and will be removed in the next major release. Use a local converter.
  anndata2ri.activate()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
[<ipython-input-4-9fc1bec6d256>](https://9uht5y5ij7t-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20231109-060126_RC00_580860867#) in <cell line: 3>()
      1 import anndata2ri
      2 anndata2ri.activate()
----> 3 get_ipython().run_line_magic('load_ext', 'rpy2.ipython')

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

[/usr/local/lib/python3.10/dist-packages/rpy2/robjects/conversion.py](https://9uht5y5ij7t-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20231109-060126_RC00_580860867#) in _raise_missingconverter(obj)
    381     by multithreading code not passing context to the thread.
    382     """
--> 383     raise NotImplementedError(_missingconverter_msg)
    384 
    385 

NotImplementedError: 
    Conversion rules for `rpy2.robjects` appear to be missing. Those
    rules are in a Python contextvars.ContextVar. This could be caused
    by multithreading code not passing context to the thread.

Look forward to learning your insights! Many thanks!

flying-sheep commented 9 months ago

The error happens before the import anndata2ri. Please check out the rpy2 issue tracker, e.g. https://github.com/rpy2/rpy2/issues/1068

ScienceComputing commented 9 months ago

The error happens before the import anndata2ri. Please check out the rpy2 issue tracker, e.g. rpy2/rpy2#1068

Thank you so much for the help!

flying-sheep commented 9 months ago

I hope you could find help about avoiding it there!