Ubuntu16+Python2.7环境下matplotlib报错No module named finance求解
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
Install the standalone
mpl_financelibrary
Since you’re using Python 2.7, make sure to usepip2(the Python 2 version of pip) for installation. First, if you don’t havepip2set up on Ubuntu 16.04, run this to install it:sudo apt-get update && sudo apt-get install python-pipThen install
mpl_finance:sudo pip2 install mpl_financeUpdate your import statements
In your Python script, replace any lines referencingmatplotlib.financewith the new standalone library:
Replace this:import matplotlib.finance as mpf # OR from matplotlib.finance import candlestick_ohlcWith this:
import mpl_finance as mpf # OR from mpl_finance import candlestick_ohlcVerify 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

