导入错误Matplotlib需要'_c_internal_utils'并且实际使用conda

问题描述 投票:0回答:1

出现此错误

    {
    "name": "ImportError",
    "message": "cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import) (c:\\Users\\Lenovo\\miniconda3\\envs\\lastresort\\Lib\\site-packages\\matplotlib\\__init__.py)",
    "stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[3], line 2
      1 import os
----> 2 import matplotlib.pyplot as plt
      3 from matplotlib.pyplot import imshow
      5 import numpy as np

File c:\\Users\\Lenovo\\miniconda3\\envs\\lastresort\\Lib\\site-packages\\matplotlib\\__init__.py:159
    155 from packaging.version import parse as parse_version
    157 # cbook must import matplotlib only within function
    158 # definitions, so it is safe to import from it here.
--> 159 from . import _api, _version, cbook, _docstring, rcsetup
    160 from matplotlib.cbook import sanitize_sequence
    161 from matplotlib._api import MatplotlibDeprecationWarning

File c:\\Users\\Lenovo\\miniconda3\\envs\\lastresort\\Lib\\site-packages\\matplotlib\\cbook.py:32
     29     from numpy import VisibleDeprecationWarning
     31 import matplotlib
---> 32 from matplotlib import _api, _c_internal_utils
     35 def _get_running_interactive_framework():
     36     \"\"\"
     37     Return the interactive framework whose event loop is currently running, if
     38     any, or \"headless\" if no event loop can be started, or None.
   (...)
     44         \"macosx\", \"headless\", ``None``.
     45     \"\"\"

ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import) (c:\\Users\\Lenovo\\miniconda3\\envs\\lastresort\\Lib\\site-packages\\matplotlib\\__init__.py)"
}

并检查了所有其他存在的问题,例如this,但条件不同。在降级到 python 3.11 matplotlib 仍然有效之前,我需要降级到 3.11,因为 3.12 和 3.13 存在需求错误(tensorflow-cpu 在 3.12 中不存在,cgi 自 3.11 以来不存在或需要我从 3.13 降级的东西)

重新安装 Matplotlib 并更新它,但仍然无法工作

检查了其他论坛,这可能与操作系统相关并且与C++引擎相关,有什么可能的解决方案吗?

python-3.x matplotlib conda
1个回答
0
投票

通过卸载matplotlib并按照常规方式再次安装matplotlib来修复,如有必要,删除

./miniconda3/envs/{env-name}/Lib/site-packages/

中的文件

如果其他人或通过其他方式找到其他详细信息,将很乐意编辑

© www.soinside.com 2019 - 2024. All rights reserved.