You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.8.10运行Matplotlib代码出现exit code 3错误求助

解决Matplotlib运行报错“Process ended with exit code 3”的方案

问题背景

32位系统,已安装Python 3.8.10及相关库,使用Thonny/Wing IDE运行Matplotlib示例代码时,仅返回Process ended with exit code 3,无其他输出。已确认路径、安装无误,重装Python和IDE未解决问题。

示例代码:

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.axis([0, 6, 0, 20])
plt.show()

输出:

Process ended with exit code 3.

排查与解决步骤

  • 检查Matplotlib后端兼容性
    32位系统下默认的TkAgg后端可能存在适配问题,先测试无界面后端验证代码逻辑:

    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
    plt.axis([0, 6, 0, 20])
    plt.savefig('test_plot.png')
    

    若能生成图片,说明是显示后端问题,可尝试切换到Qt5Agg后端(需先安装32位PyQt5):

    pip install pyqt5==5.15.4 --only-binary :all:
    

    之后在代码开头添加matplotlib.use('Qt5Agg')即可。

  • 强制安装兼容的32位依赖库
    Python 3.8的32位版本对部分新版本库支持有限,指定稳定兼容版本重装:

    pip install --force-reinstall matplotlib==3.4.3 numpy==1.21.6
    
  • 核对IDE的解释器配置

    • Thonny:点击「运行」→「选择解释器」,确认选中32位Python 3.8.10
    • Wing IDE:通过「Project」→「Project Properties」→「Python Executable」指定正确的32位Python路径
  • 在命令行直接运行代码
    避开IDE可能的输出屏蔽,在命令行执行:

    python test_plot.py
    

    查看是否有更详细的报错信息,定位具体问题。

内容的提问来源于stack exchange,提问作者Jae

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 04:30:07