Metaclass Conflict from trying to Import Scanpy

Hi there! I was trying to work on my code but I am getting an import error from trying to import scanpy that I have never previously gotten. The issue is a type error with a metaclass conflict between the Axes class and the SubplotBase class.

I thought perhaps this issue was caused due to a new update in the scanpy environment and I was wondering as to why this is occurring and how I might be able to fix it. I tried installing previous versions of scanpy instead as well as the other packages but this did not resolve my issue.

My code was working perfectly fine beforehand and I have not made any changes to the code itself. Besides the issue is within the import itself. Any insight would be extremely helpful thanks so much!

This is the full error shown below:


TypeError Traceback (most recent call last)
in
5 import numpy as np
6 import pandas as pd
----> 7 import scanpy as sc
8 import os
9 import anndata

3 frames
/usr/local/lib/python3.8/dist-packages/scanpy/init.py in
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
18

/usr/local/lib/python3.8/dist-packages/scanpy/plotting/init.py in
----> 1 from ._anndata import (
2 scatter,
3 violin,
4 ranking,
5 clustermap,

/usr/local/lib/python3.8/dist-packages/scanpy/plotting/_anndata.py in
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

/usr/local/lib/python3.8/dist-packages/scanpy/plotting/_utils.py in
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

See `TypeError: metaclass conflict`: matplotlib v3.7.0 is incompatible with scanpy · Issue #2411 · scverse/scanpy · GitHub

To workaround, downgrade matplotlib to <3.7

The people who reply on here are truly god sends, I was banging my head on the wall for hours trying to resolve this issue.

I truly, truly appreciate the help so much, thank you. :slight_smile:

Yes thats true and it helps everyone else who might face the issue in future