导入Pandas与PandasGUI触发ImportError循环导入问题求助
解决PandasGUI导入matplotlib循环导入错误的方案
问题描述
按照PandasGUI文档运行代码:
import pandas as pd from pandasgui import show df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9]}) show(df)
触发循环导入错误:
ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import) (C:\ProgramData\Anaconda3\envs\Test\lib\site-packages\matplotlib\__init__.py)
修改导入方式为import pandasgui后仍报错,环境配置:
- Python 3.11.4(Anaconda打包)
- Pandas 2.0.3
- PandasGUI 0.2.14
解决方案
提前导入matplotlib打破循环
在所有导入语句前先导入matplotlib,强制完成其初始化:import matplotlib import pandas as pd from pandasgui import show df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9]}) show(df)降级matplotlib版本
该问题多出现于matplotlib 3.7.x与高版本Python/Pandas的组合,降级到3.6.3可解决:pip install matplotlib==3.6.3升级PandasGUI到最新版
旧版PandasGUI未适配Python 3.11和Pandas 2.0.x,升级后可修复兼容性问题:pip install --upgrade pandasgui创建全新虚拟环境
Anaconda环境可能存在依赖冲突,新建环境重新安装依赖:conda create -n pandasgui_env python=3.10 pandas=2.0.3 pandasgui matplotlib conda activate pandasgui_env注:Python 3.10对旧依赖的兼容性优于3.11,可避开部分适配问题。
内容的提问来源于stack exchange,提问作者PSt
相关产品推荐
相关产品推荐

