Python3.9.2安装matplotlib==2.0.2出现exit code:1错误求助
解决matplotlib==2.0.2安装时缺少freetype/png头文件的问题
你的问题核心是matplotlib编译安装时依赖的C/C++开发库缺失,不同操作系统的解决方式如下:
Debian/Ubuntu 系列
- 先安装所需的开发依赖包:
sudo apt-get install libfreetype6-dev libpng-dev - 重新执行matplotlib安装命令:
pip install matplotlib==2.0.2
RHEL/CentOS/Fedora 系列
- 安装对应开发依赖:
# CentOS/RHEL sudo yum install freetype-devel libpng-devel # Fedora sudo dnf install freetype-devel libpng-devel - 重新执行安装:
pip install matplotlib==2.0.2
macOS
- 使用Homebrew安装依赖:
brew install freetype libpng - 重新执行安装命令:
pip install matplotlib==2.0.2
Windows
Windows下编译依赖配置繁琐,推荐直接安装预编译的wheel包:
- 下载适配Python3.9的matplotlib==2.0.2 wheel文件(注意匹配系统位数,如x64)
- 执行本地安装:
pip install 你的wheel文件路径/matplotlib-2.0.2-cp39-none-win_amd64.whl
额外建议
matplotlib 2.0.2是较旧版本,官方对Python3.9的支持有限,若业务允许,建议安装支持Python3.9的更高版本(如>=3.3.0),可避免编译依赖问题:
pip install matplotlib>=3.3.0
内容的提问来源于stack exchange,提问作者hch
相关产品推荐
相关产品推荐

