Matplotlib安装失败求助:执行pip安装命令时触发异常
Hey Vijay, looks like you’re hitting a roadblock installing matplotlib with Python 2.7. The core issue here is that Python 2.7 reached end-of-life in 2020, and all modern versions of matplotlib (3.0+) no longer support it. Your pip command is trying to pull the latest incompatible release, which is causing the error.
Here are two actionable solutions to get this working:
Option 1: Install a Python 2.7-compatible matplotlib version
The last matplotlib release that supports Python 2.7 is 2.2.5. Run this specific command to install it:
python -mpip install matplotlib==2.2.5
If you run into system dependency errors (common on Ubuntu/Debian), first install these required packages:
sudo apt-get install libfreetype6-dev libpng-dev python-dev
Then retry the matplotlib install command.
Option 2: Upgrade to Python 3 (Highly Recommended)
Since Python 2.7 is no longer maintained, switching to Python 3 is the best long-term fix. All recent matplotlib versions work seamlessly with Python 3.6+. To install matplotlib on Python 3:
python3 -mpip install matplotlib
If you don’t have Python 3 installed yet, grab it with:
sudo apt-get install python3 python3-pip
Quick note about your pip version
Your current pip is for Python 2.7 and likely outdated. If you still need to use Python 2.7, upgrade pip first to handle older package versions properly:
python -mpip install --upgrade pip==20.3.4
This is the final pip release that supports Python 2.7.
Hope this resolves your issue!
内容的提问来源于stack exchange,提问作者Vijay Sengar

