Encountering error when loading scanpy?
2
3
Entering edit mode
22 months ago
bioinfo ▴ 150

Hello,

I have been using scanpy to analyze some single cell data using google colab.

Everything was working ok but all of a sudden I rerun the notebook and now when I try to import scanpy I get the error below. What could be causing this?

---------------------------------------------------------------------------
TypeError                                 
Traceback (most recent call last)
<ipython-input-12-04a6a9427c98> in <module>
      2 import numpy as np
      3 import pandas as pd
----> 4 import scanpy as sc
      5 import matplotlib.pyplot as plt
      6 get_ipython().run_line_magic('matplotlib', 'inline')

3 frames
/usr/local/lib/python3.8/dist-packages/scanpy/plotting/_utils.py in
<module>
     33 
     34 
---> 35 class _AxesSubplot(Axes, axes.SubplotBase, ABC):
     36     """Intersection between Axes and SubplotBase: Has methods of both"""
     37 

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Thank you

scanpy single-cell scRNA-seq • 6.2k views
ADD COMMENT
2
Entering edit mode

Hei,

I am having same Metaclass issue in jupyter-notebook. I installed scanpy using pip and import scanpy as sc. then :

to me

TypeError                                 Traceback (most recent call last)
Cell In[9], line 2
      1 import anndata
----> 2 import scanpy

File /usr/local/lib/python3.10/dist-packages/scanpy/__init__.py:16
     14 from . import tools as tl
     15 from . import preprocessing as pp
---> 16 from . import plotting as pl
     17 from . import datasets, logging, queries, external, get, metrics, experimental
     19 from anndata import AnnData, concat

File /usr/local/lib/python3.10/dist-packages/scanpy/plotting/__init__.py:1
----> 1 from ._anndata import (
      2     scatter,
      3     violin,
      4     ranking,
      5     clustermap,
      6     tracksplot,
      7     dendrogram,
      8     correlation_matrix,
      9     heatmap,
     10 )
     11 from ._dotplot import DotPlot, dotplot
     12 from ._matrixplot import MatrixPlot, matrixplot

File /usr/local/lib/python3.10/dist-packages/scanpy/plotting/_anndata.py:28
     26 from .._utils import sanitize_anndata, _doc_params, _check_use_raw
     27 from .._compat import Literal
---> 28 from . import _utils
     29 from ._utils import scatter_base, scatter_group, setup_axes, check_colornorm
     30 from ._utils import ColorLike, _FontWeight, _FontSize

File /usr/local/lib/python3.10/dist-packages/scanpy/plotting/_utils.py:35
     29 _FontSize = Literal[
     30     'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'
     31 ]
     32 VBound = Union[str, float, Callable[[Sequence[float]], float]]
---> 35 class _AxesSubplot(Axes, axes.SubplotBase, ABC):
     36     """Intersection between Axes and SubplotBase: Has methods of both"""
     39 # -------------------------------------------------------------------------------
     40 # Simple plotting functions
     41 # -------------------------------------------------------------------------------

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
ADD REPLY
1
Entering edit mode

Hey there guys! I am having the exact same issue and I have been banging my head against the wall for the past 6 hours trying to fix it. I tried installing an older version of scanpy and looked at my old outputs when importing and matching the versions of all the prior import dependencies but with no avail.

Currently scouring through the init, anndata, and utils.py files, one thing I noticed was that a lot of the imports within them are trying to import classes that are not being recognized by pyright. This may be a possible link to it all and I am trying to see what paths are not being recognized and am trying to add them into the config.json file. Not sure if this will work but will update if else.

I saw this post but I did not realize how recent it was posted and realizing that this is the first post of the issue that I can find other than the one I made on scverse and considering that it was posted 9 hours ago I am guessing it is likely some bug in the new update for scanpy?

I never encountered this problem before and it started to me today yesterday as well. I am using google collab as well. Hopefully if more of us can reach out to the scanpy team it would streamline the time it takes for this to get resolved. So I encourage everyone who is also having this issue to contact them as well!

Furthermore, if it is an issue with a possible update I don't know why installing a prior version of scanpy would not fix the issue. But it didn't for me! Maybe try doing that too and see if it works on your guys end, and if it does please post the version that worked!

Here is my error, our errors seem to be referenced in different places within the plotting ._utils but its all seems to be from plotting ._util and we are all getting the same error regarding the metaclasses.

Great to know I'm not the only one struggling hope to hear from the team or anyone else about this issue soon!

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-b2ffb3b00935> in <module>
     17 import anndata
     18 import matplotlib
---> 19 import scanpy as sc
     20 import os
     21 from google.colab import drive

3 frames
/usr/local/lib/python3.8/dist-packages/scanpy/plotting/_utils.py in <module>
     34 
     35 
---> 36 class _AxesSubplot(Axes, axes.SubplotBase, ABC):
     37     """Intersection between Axes and SubplotBase: Has methods of both"""
     38 

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
ADD REPLY
0
Entering edit mode

Use the 101010 button (NOT the double quote button) to format code. The former is for code, the latter is to quote something someone said elsewhere. I've fixed it for you (as best as I can - the double quote options wreks havoc on new lines) this time

ADD REPLY
6
Entering edit mode
22 months ago
koupar12345 ▴ 60

Hey y'all a fellow from scverse replied to my question and resolved our issue.

The issue seems to be that matplotlib version 3.7 is incompatible with scanpy version 1.9.1

As such, to resolve this issue you need to do is install a version of matplotlib thats older than 3.7. I used version 3.6 and that completely eradicated the metaclass issue.

pip install 'matplotlib == 3.6'

For further reference see the Github page:

https://github.com/scverse/scanpy/issues/2411

ADD COMMENT
1
Entering edit mode

Thanks koupar, it worked.

ADD REPLY
0
Entering edit mode

That worked. Thank you

ADD REPLY
2
Entering edit mode
22 months ago
Paul Fisher ▴ 20

This is due to an incompatibility between scanpy and a newly-released version of matplotlib, reported as scanpy bug #2411.

To fix this, you can install the earlier version of matplotlib:

pip install 'matplotlib<3.7'

You can provide a similar specification in a pyproject.toml/setup.py/etc. file, which is how we worked around it in our own repository.

ADD COMMENT
0
Entering edit mode

Now I am getting the error for cmap colour in plot

UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
ADD REPLY

Login before adding your answer.

Traffic: 2314 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6