ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib'

Viewed 290

Today I created a new Conda env based on PyPy using this command:

conda create -pypy1 pypy

Then after activation, I started to install packages using the conda-forge channel. For example, I installed matplotlib using the conda-forge channel, and when I enter conda list matplotlib in the activated Conda env, I get this:

# packages in environment at C:\Users\Shayan\ypy1:
#
# Name                    Version                   Build  Channel
matplotlib-base           3.5.1            py38hd77b12b_1
matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge

But when I try to import matplotlib, I get this error:

>>> import matplotlib
----> 1 import matplotlib

File c:\Users\Shayan\ypy1\lib\site-packages\matplotlib\__init__.py:109, in <module>
    105 from packaging.version import parse as parse_version
    107 # cbook must import matplotlib only within function
    108 # definitions, so it is safe to import from it here.
--> 109 from . import _api, _version, cbook, docstring, rcsetup
    110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
    111 from matplotlib.cbook import mplDeprecation  # deprecated

File c:\Users\Shayan\ypy1\lib\site-packages\matplotlib\cbook\__init__.py:31, in <module>
     28 import numpy as np
     30 import matplotlib
---> 31 from matplotlib import _api, _c_internal_utils
     32 from matplotlib._api.deprecation import (
     33     MatplotlibDeprecationWarning, mplDeprecation)
     36 @_api.deprecated("3.4")
     37 def deprecated(*args, **kwargs):

ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import) (c:\Users\Shayan\ypy1\lib\site-packages\matplotlib\__init__.py)

How can I fix this, and what's the problem?

1 Answers

The command conda create -n pypy1 pypy will use the default python version 3.8. The migration on conda-forge for pypy3.8/3.9 packages started a few months ago but matplotlib has not yet been migrated. I am not sure what package you got, but it is not one that can work with pypy3.8.

You can tell conda "please use pypy3.7" via conda create -pypy1 pypy python=3.7

Related