错误:无法构建hnswlib的轮子,这是安装基于pyproject.toml的项目所必需的。

35
我正在尝试在Mac上安装embeddinghub(尝试了pip3 install embeddinghub和pip3 install pandas embeddinghub protobuf),但是我得到了同样的错误,说“无法为hnswlib构建轮子,这是安装基于pyproject.toml的项目所需的”。 我找不到任何关于hnswlib的解决方案。 我已经尝试了很多关于PEP517和为其他事物构建轮子的解决方案,但是没有一个解决方案能够帮助我。 这是完整的错误:
错误
Collecting pandas
  Using cached pandas-1.5.0-cp310-cp310-macosx_11_0_arm64.whl (10.8 MB)
Collecting embeddinghub
  Using cached embeddinghub-0.0.1.post12-py3-none-any.whl
Collecting protobuf
  Using cached protobuf-4.21.7-cp37-abi3-macosx_10_9_universal2.whl (484 kB)
Collecting pytz>=2020.1
  Using cached pytz-2022.4-py2.py3-none-any.whl (500 kB)
Collecting python-dateutil>=2.8.1
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting numpy>=1.21.0
  Using cached numpy-1.23.3-cp310-cp310-macosx_11_0_arm64.whl (13.3 MB)
Collecting grpcio==1.40.0
  Using cached grpcio-1.40.0-cp310-cp310-macosx_10_10_universal2.whl
Collecting hnswlib==0.5.2
  Using cached hnswlib-0.5.2.tar.gz (29 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy>=1.21.0
  Using cached numpy-1.21.1-cp310-cp310-macosx_12_0_universal2.whl
Collecting six==1.16.0
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: hnswlib
  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
  ╰─> [17 lines of output]
      running bdist_wheel
      running build
      running build_ext
      creating var
      creating var/folders
      creating var/folders/3h
      creating var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn
      creating var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/Users/s/venv/include -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c /var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T/tmp5hthbs8k.cpp -o var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T/tmp5hthbs8k.o -std=c++14
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/Users/s/venv/include -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c /var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T/tmpipibvgip.cpp -o var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T/tmpipibvgip.o -fvisibility=hidden
      building 'hnswlib' extension
      creating build
      creating build/temp.macosx-10.9-universal2-cpython-310
      creating build/temp.macosx-10.9-universal2-cpython-310/python_bindings
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/private/var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T/pip-build-env-hhht57g1/overlay/lib/python3.10/site-packages/pybind11/include -I/private/var/folders/3h/0w98c6q56bl4x4c2qm31np_c0000gn/T/pip-build-env-hhht57g1/overlay/lib/python3.10/site-packages/numpy/core/include -I./hnswlib/ -I/Users/s/venv/include -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c ./python_bindings/bindings.cpp -o build/temp.macosx-10.9-universal2-cpython-310/./python_bindings/bindings.o -O3 -march=native -stdlib=libc++ -mmacosx-version-min=10.7 -DVERSION_INFO=\"0.5.2\" -std=c++14 -fvisibility=hidden
      clang: error: the clang compiler does not support '-march=native'
      error: command '/usr/bin/clang' 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
19个回答

47

尝试设置一个环境变量:

export HNSWLIB_NO_NATIVE=1  

然后重试...


2
这适用于苹果MacBook Pro(2.9 GHz四核Intel Core i7)Ventura 13.1。 - JJ Fantini
1
同样适用于我使用的2.3 GHz 8-Core Intel Core i9 MacBook Pro Ventura 13.2.1。 - Sean
3
这在WSL Ubuntu上不起作用。 - undefined
2
这在WSL Ubuntu上不起作用。 - James Shapiro
2
在我的M1 MacBook Air上运行良好,谢谢 :) - nsprenkle
显示剩余4条评论

46

感谢您的支持。我使用了这个解决方案来解决私有GPT的安装问题。 - olgunyldz
1
这对我来说是解决方案,谢谢! - Taylan Gezici
2
你是怎么找出这个解决方案的?太棒了... - renakre
1
我对如何能够弄清楚这件事感到困惑不已。 - ocean800
试错法! - Varada
好的!谢谢!这个方法有效。对我来说看起来有些不同,我有一个漂亮的图形界面,比你的选项多。我基本上安装了所有东西,大部分看起来都很有用,而且我有足够的空间。 - undefined

12
在Ubuntu中,这些命令解决了这个问题,也许Mac的替代方案也会很有用:
sudo apt install python3-dev
sudo apt-get install build-essential -y

1
这对我来说没有解决WSL Ubuntu的问题。 - James Shapiro
1
在Ubuntu 22.04中修复了问题。 - Vinod
为我在WSL Ubuntu上修复了。 - aherrick
在尝试安装ChromaDB时,修复了Ubuntu 22.04中的问题。 - undefined

4

对于Ubuntu 20及以上版本,请安装与您正在使用的Python版本相应的开发工具和构建必需品:

对于Python3.10:

sudo apt install python3.10-dev && sudo apt-get install build-essential -y

对于Python3.11版本:
sudo apt install python3.11-dev && sudo apt-get install build-essential -y

3
好的,明白了...所以对于我的使用情况来说,这是一个冗长的解决方案,但是我会尝试类似上面的方法:
1. 下载https://visualstudio.microsoft.com/visual-cpp-build-tools/。 2. 导航到“个别组件”,找到并选择那些被其他人提到的组件。

enter image description here

并且

enter image description here

3. 完成安装 4. 重新启动电脑 5. 然后执行 !pip install chromadb==0.3.26,选择这个特定的版本对我来说有效。我认为最新的版本在此时可能不起作用,尽管我可能错了。
无法解决我的问题,但对其他人有用的解决方案:
1. !pip install wheel 2. !pip install --upgrade setuptools

1

1

1
降级Python到3.10.10
export HNSWLIB_NO_NATIVE=1 
pip install HNSWLIB

你的回答可以通过提供更多支持性信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人能够确认你的回答是否正确。你可以在帮助中心找到关于如何撰写好回答的更多信息。 - Community

1

如果您使用的是Windows,请尝试set HNSWLIB_NO_NATIVE=1


这并没有回答问题。一旦你拥有足够的声望,你就可以评论任何帖子;相反,提供不需要提问者澄清的答案。- 来自审查 - Jan

0

未找到Clang编译器。 请检查C/C++版本clang -v。如果未找到

sudo xcode-select --install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接