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

Ubuntu16+Python2.7环境下matplotlib报错No module named finance求解

Fixing "matplotlib: No module named finance" in Ubuntu 16.04 + Python 2.7 + matplotlib 2.2.0

Hey there, I’ve run into this exact issue before—let’s get it sorted out quickly!

Why this happens

Starting with matplotlib 2.0.0, the finance module was pulled out of the main matplotlib package and turned into a standalone library called mpl_finance. That’s why your import is failing even though you have matplotlib installed properly.

Step-by-step fix

  1. Install the standalone mpl_finance library
    Since you’re using Python 2.7, make sure to use pip2 (the Python 2 version of pip) for installation. First, if you don’t have pip2 set up on Ubuntu 16.04, run this to install it:

    sudo apt-get update && sudo apt-get install python-pip
    

    Then install mpl_finance:

    sudo pip2 install mpl_finance
    
  2. Update your import statements
    In your Python script, replace any lines referencing matplotlib.finance with the new standalone library:
    Replace this:

    import matplotlib.finance as mpf
    # OR
    from matplotlib.finance import candlestick_ohlc
    

    With this:

    import mpl_finance as mpf
    # OR
    from mpl_finance import candlestick_ohlc
    
  3. Verify the fix
    Open a Python 2.7 shell and test the import to confirm everything works:

    import mpl_finance
    print(mpl_finance.__version__)  # Should output a version number without errors
    

If you hit permission issues during installation, double-check you’re using sudo for system-wide installs, or use a virtual environment if you’d rather avoid modifying system-level packages.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:02:33