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

使用Poetry安装pymgclient时遇Python.h缺失错误求助

解决pymgclient安装时Python.h缺失的编译错误

问题重现

使用Poetry安装pymgclient时触发编译失败,关键错误日志如下:

src/column.h:18:10: fatal error: Python.h: No such file or directory

完整错误输出:

x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DMGCLIENT_STATIC_DEFINE= -I/tmp/pip-req-build-mkeehpn7/build/temp.linux-x86_64-3.9/mgclient_install/include -I/home/josip/Memgraph-Repos/feature-not-bug/.venv/include -I/usr/include/python3.9 -c src/column.c -o build/temp.linux-x86_64-3.9/src/column.o

In file included from src/column.c:15:
src/column.h:18:10: fatal error: Python.h: No such file or directory
18 | #include <Python.h>
|          ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

问题原因

这不是Python 3.9.5版本的问题,而是系统缺少Python 3.9的开发头文件包。Python.h是编译C扩展类型Python包的必要文件,默认的Python运行时包不包含该文件。

解决方案

Debian/Ubuntu系系统

执行以下命令安装Python 3.9开发依赖:

sudo apt update && sudo apt install python3.9-dev

安装完成后重新运行Poetry安装命令:

poetry add pymgclient

其他Linux发行版

  • RHEL/CentOS/Fedora:
    sudo dnf install python39-devel
    
  • Arch Linux:
    sudo pacman -S python39
    

(Arch的Python包默认包含开发头文件)

额外检查

若系统存在多版本Python,确认Poetry使用的虚拟环境绑定的是Python 3.9:

poetry run python --version

若版本不符,指定Python版本创建虚拟环境:

poetry env use python3.9

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 15:25:14