gpt4 book ai didi

hnswlib package issue while installing chromadb in ubuntu(在ubuntu中安装chromadb时出现hnswlib包问题)

转载 作者:bug小助手 更新时间:2023-10-25 13:17:38 38 4
gpt4 key购买 nike



I am using ubuntu 20.04 focal and trying to install chromadb by using 'pip install chromdb' but I am getting following error

我正在使用ubuntu 20.04焦点,并试图通过使用‘pip install chromdb’来安装chromadb,但我收到以下错误


  Building wheel for hnswlib (pyproject.toml) ... error
error: subprocess-exited-with-error

× Building wheel for hnswlib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
running bdist_wheel
running build
running build_ext
creating 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
building 'hnswlib' extension
creating build
creating build/temp.linux-x86_64-cpython-310
creating 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
In file included from /tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../attr.h:13,
from /tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/detail/class.h:12,
from /tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/pybind11.h:13,
from /tmp/pip-build-env-izlfj5h4/overlay/lib/python3.10/site-packages/pybind11/include/pybind11/functional.h:12,
from ./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: fatal error: Python.h: No such file or directory
266 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for hnswlib
Failed to build hnswlib
ERROR: Could not build wheels for hnswlib, which is required to install pyproject.toml-based projects

I have tried to update the gcc complier too but error still persists

我也尝试过更新GCC编译器,但错误仍然存在


I tried to update the ubuntu and its gcc complier

我试着更新Ubuntu和它的GCC编译器


更多回答
优秀答案推荐

The error message suggests that the installation of chromdb is failing due to a problem with building the hnswlib wheel. The error specifically mentions that it cannot find the Python.h header file.

该错误消息表明,由于构建hnswlib轮的问题,chromdb的安装失败。该错误特别提到它找不到Python.h头文件。


To resolve this issue, you need to install the development headers for Python. You can do this by running the following command (since you are on ubuntu):

要解决此问题,您需要安装Python的开发头文件。您可以通过运行以下命令来完成此操作(因为您使用的是ubuntu):


sudo apt-get install python3-dev

This command will install the necessary development files for Python. Afterward, you can try installing chromdb again using pip install chromdb.

该命令将为Python安装必要的开发文件。然后,您可以使用pip install chromdb再次尝试安装chromdb。


If you still encounter the same error, you can try updating your pip version to the latest version by running:

如果您仍然遇到相同的错误,您可以尝试通过运行以下命令将pip版本更新到最新版本:


pip install --upgrade pip

Then attempt the installation again using pip install chromdb.

然后使用pip install chromdb再次尝试安装。


If the issue persists, please provide any additional error messages or logs you receive during the installation process, as they might provide further insight into the problem. I hope this helps :)

如果问题仍然存在,请提供您在安装过程中收到的任何其他错误消息或日志,因为它们可能提供对问题的进一步了解。我希望这会对您有所帮助:)



As suggested by @Eldinur the Kolibri in their answer, installing development headers for Python does solve this.
Although You may have to run python version-specific installation.

正如@Eldinur the Kolibri在他们的回答中所建议的那样,为Python安装开发头文件确实解决了这个问题。尽管您可能必须运行特定于Python版本的安装。


For python3.8, it will be like:

对于python3.8,它将类似于:


sudo apt-get install python3.8-dev


I was having almost the exact same error message when trying pip install chromadb (the only differences were I'm using python3.11, looks like you're on 3.10. Second, it looks like you're using Langchain and I'm running from a python script).

当我尝试pip安装chromadb时,我收到了几乎完全相同的错误信息(唯一的区别是我使用的是python3.11,看起来您使用的是3.10。其次,看起来您使用的是langchain,而我运行的是一个python脚本)。


What ended up working for me was sudo apt install python3.11-dev, you should try installing python3.10. I had also tried sudo apt install python3-dev and this didn't work (which I think means I don't have 3.11 set as default, not sure).

最终对我起作用的是sudo apt安装python3.11-dev,您应该尝试安装python3.10。我还尝试了sudo apt安装python3-dev,但没有成功(我认为这意味着我没有将3.11设置为默认设置,不确定)。


I'd recommend trying this and if that doesn't work, try running a script outside of langchain (chromadb's homepage has a quick example). If it works standalone but not in langchain then you know it's langchain that's now the issue.

我建议尝试这样做,如果不起作用,可以尝试在langchain之外运行一个脚本(chromadb的主页有一个简单的例子)。如果它可以独立运行,但不能在langchain中运行,那么现在问题就出在langchain上了。



This worked for me:

这对我来说很管用:


sudo apt-get install python3-dev
python3.10 -m pip install --upgrade pip
sudo apt install build-essential
python3.10 -m pip install hnswlib


I tryied all the solutions here and many others in the web. After some try and error in my computer as experiment, the only thing that worked for me was using python 3.8 and it's pip to install create and use a virtual environment that will install chromadb in it. I tried python 3.11 and 3.10 but none of them worked.

我在这里尝试了所有的解决方案,并在网络上尝试了许多其他的解决方案。作为实验,在我的计算机上进行了一些尝试和错误之后,唯一对我起作用的是使用python3.8和它的安装、创建和使用将在其中安装chromadb的虚拟环境。我尝试了python3.11和3.10,但它们都不起作用。



The error message indicates that the installation of 'chromdb' is encountering a failure attributed to the construction of the 'hnswlib' wheel. The error explicitly states its inability to locate the 'Python.h' header file.

该错误消息表明‘chromdb’的安装遇到了可归因于‘hnswlib’轮构造的失败。该错误明确指出它无法找到‘Python.h’头文件。


To rectify this matter, the resolution involves procuring the development headers tailored for Python. This can be executed by executing the ensuing command (presuming you're utilizing Ubuntu):

为了纠正这个问题,该解决方案涉及采购为Python量身定做的开发头文件。这可以通过执行下面的命令来执行(假设您正在使用Ubuntu):


sudo apt-get install python3-dev

This command's execution will facilitate the acquisition of the requisite development files pertinent to Python. Once accomplished, make another attempt at installing 'chromdb' using the subsequent pip command:

该命令的执行将有助于获取与Python相关的必要开发文件。完成后,使用后续的pip命令再次尝试安装‘chromdb’:


pip install chromdb

Should the identical error persist, consider elevating your 'pip' version to the most current iteration through the command:

如果相同的错误仍然存在,请考虑通过以下命令将‘pip’版本升级到最新的迭代:


pip install --upgrade pip

Subsequently, endeavor once more to carry out the installation of 'chromdb' utilizing 'pip'.

随后,再次努力使用‘pip’执行‘chromdb’的安装。


I hope this helps!

我希望这能帮到你!


更多回答

I tried to install python3-dev and after I also tried to upgrade pip but the same error is persists

我尝试安装python3-dev,在我也尝试升级pip之后,仍然出现相同的错误

@Sinister_ Hmm I don't know. Maybe try sudo apt-get install build-essential as well and pip install numpy and sudo apt-get install libomp-dev. If nothing helps (then I can't help you any further) and there might be a compatibility issue with chromdb and your ubuntu version (but I doubt that).

@Sinister_ Hmm我不知道。也可以试试sudo apt-get install build-essential,pip install numpy和sudo apt-get install libomp-dev。如果没有什么帮助(那么我不能帮助你更多),可能有一个与chromdb和你的ubuntu版本的兼容性问题(但我怀疑)。

I tried everything but nothing worked then I tried to locate Python.h by using 'locate Python.h' and I found it in 'include' folder inside my python package but there were no Python.h file in my virtual env include folder so I copied all the files from include folder to the virtual env include folder and then it worked

我尝试了所有的方法,但都没有奏效,然后我尝试使用‘Locate Python.h’来查找Python.h,我在我的python包中的‘Include’文件夹中找到了它,但在我的虚拟env Include文件夹中没有Python.h文件,所以我将所有文件从Include文件夹复制到了虚拟env Include文件夹,然后它就奏效了

Can you please explain your solution a bit more like how did you copy the file and where did you copy it from @Sinister_ ?

您能更详细地解释一下您的解决方案吗?比如您是如何复制文件的,以及从@sinister_复制到了哪里?

On RHEL, install like that: sudo yum install python3-devel. It solved my issue

在RHEL上,这样安装:sudo yum安装python3-devel。它解决了我的问题

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com