Ubuntu 20.04安装Chromadb时hnswlib编译失败求助
解决Ubuntu 20.04安装Chromadb时hnswlib编译找不到Python.h的问题
在Ubuntu 20.04 Focal系统执行pip install chromadb时,构建hnswlib的wheel失败,编译阶段提示找不到Python.h文件,已更新系统和gcc但问题未解决。详细报错信息如下:
构建hnswlib的wheel(pyproject.toml)... 错误 错误:子进程退出码异常 × 构建hnswlib的wheel(pyproject.toml)未成功运行。 │ 退出码:1 ╰─> [21行输出] 运行bdist_wheel 运行build 运行build_ext 创建tmp目录 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 -fPIC -I/home/namanc/codes/langchian_chromadb/venv/include -I/usr/include/python3.10 -c /tmp/tmp822lkln8.cpp -o tmp/tmp822lkln8.o -std=c++14 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 -fPIC -I/home/namanc/codes/langchian_chromadb/venv/include -I/usr/include/python3.10 -c /tmp/tmpw33wg22s.cpp -o tmp/tmpw33wg22s.o -fvisibility=hidden 构建'hnswlib'扩展 创建build目录 创建build/temp.linux-x86_64-cpython-310目录 创建build/temp.linux-x86_64-cpython-310/python_bindings目录 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 -fPIC -I/tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include -I/tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/numpy/core/include -I./hnswlib/ -I/home/namanc/codes/langchian_chromadb/venv/include -I/usr/include/python3.10 -c ./python_bindings/bindings.cpp -o build/temp.linux-x86_64-cpython-310/./python_bindings/bindings.o -O3 -fopenmp -DVERSION_INFO="0.7.0" -std=c++14 -fvisibility=hidden 从/tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../attr.h:13引入文件时, 来自/tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/detail/class.h:12, 来自/tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/pybind11.h:13, 来自/tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/functional.h:12, 来自./python_bindings/bindings.cpp:2: /tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../detail/common.h:266:10: 致命错误:Python.h:没有那个文件或目录 266 | #include <Python.h> | ^~~~~~~~~~ 编译终止。 错误:命令'/usr/bin/x86_64-linux-gnu-gcc'执行失败,退出码1 [输出结束] 注意:此错误源自子进程,大概率不是pip的问题。 错误:构建hnswlib的wheel失败 构建hnswlib失败 错误:无法为hnswlib构建wheel,这是安装基于pyproject.toml的项目所必需的
解决方法
- 安装对应Python版本的开发包(你的环境是Python3.10):
sudo apt-get install python3.10-dev - 重新执行Chromadb安装命令:
pip install chromadb
如果上述命令无效,可尝试安装通用Python开发依赖及编译工具:
sudo apt-get install python3-dev build-essential
原因说明
Ubuntu默认仅安装Python运行环境,当编译需要调用Python C接口的扩展库(如hnswlib)时,必须安装对应的开发包,该包包含编译所需的Python.h头文件及链接库。
内容的提问来源于stack exchange,提问作者Sinister _
相关产品推荐
相关产品推荐

