Python 3.11 X86环境安装matplotlib失败求助(勿用conda)
Python 3.11 X86环境执行pip install matplotlib时,因无法下载freetype依赖包导致编译失败,报错信息如下:
error: Failed to download any of the following: ['https://downloads.sourceforge.net/project/freetype/freetype2/2.6.1/freetype-2.6.1.tar.gz',
'https://download.savannah.gnu.org/releases/freetype/freetype-2.6.1.tar.gz',
'https://download.savannah.gnu.org/releases/freetype/freetype-old/freetype-2.6.1.tar.gz'].
Please download one of these urls and extract it into 'build/' at the top-level of the source repository.
[end of output]
ERROR: Failed building wheel for matplotlib
ERROR: Could not build wheels for matplotlib, which is required to install pyproject.toml-based projects
注:此错误源自子进程,非pip本身问题,且禁用conda解决。
方法一:手动提供freetype依赖完成编译
- 从给出的三个地址中任选一个下载
freetype-2.6.1.tar.gz压缩包 - 在执行
pip install matplotlib的当前目录下,创建名为build的文件夹 - 将下载的压缩包解压,把完整的
freetype-2.6.1文件夹放入build目录 - 重新执行
pip install matplotlib,pip会自动调用本地的freetype包完成编译
方法二:安装预编译wheel包(推荐,跳过源码编译)
- 先升级pip到最新版本:
python -m pip install --upgrade pip - 执行命令强制安装预编译包,避免源码编译环节:
pip install matplotlib --only-binary :all:
内容的提问来源于stack exchange,提问作者Ku Chow

