如何解决错误:无法为 hdbscan 构建轮子,这是安装基于 pyproject.toml 的项目所必需的

我正在尝试安装 bertopic,但出现此错误:

 pip install bertopic

    Collecting bertopic
>           Using cached bertopic-0.11.0-py2.py3-none-any.whl (76 kB)
>         Collecting hdbscan>=0.8.28
>           Using cached hdbscan-0.8.28.tar.gz (5.2 MB)
>           Installing build dependencies: started
>           Installing build dependencies: finished with status 'done'
>           Getting requirements to build wheel: started
>           Getting requirements to build wheel: finished with status 'done'
>           Preparing metadata (pyproject.toml): started
>           Preparing metadata (pyproject.toml): finished with status 'done'
>         Requirement already satisfied: tqdm>=4.41.1 in c:usersmartin kunthanaconda3libsite-packages (from bertopic) (4.62.3)
>         Collecting umap-learn>=0.5.0
>           Using cached umap_learn-0.5.3-py3-none-any.whl
>         Requirement already satisfied: scikit-learn>=0.22.2.post1 in c:usersmartin kunthanaconda3libsite-packages (from bertopic)
> 
(0.24.2)
>     

    Requirement already satisfied: numpy>=1.20.0 in c:usersmartin kunthanaconda3libsite-packages (from bertopic)
> (1.20.3)
>         Collecting plotly>=4.7.0
>           Using cached plotly-5.9.0-py2.py3-none-any.whl (15.2 MB)
>         Requirement already satisfied: pandas>=1.1.5 in c:usersmartin kunthanaconda3libsite-packages (from bertopic)
> (1.3.4)
>         Collecting pyyaml<6.0
>         Note: you may need to restart the kernel to use updated packages.
>           error: subprocess-exited-with-error

 >           

>       

        Building wheel for hdbscan (pyproject.toml) did not run successfully.
>           exit code: 1
>           
>           [40 lines of output]
>           running bdist_wheel
>           running build
>           running build_py
>           creating build
>           creating buildlib.win-amd64-cpython-39
>           creating buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscanflat.py -> buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscanhdbscan_.py -> buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscanplots.py -> buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscanprediction.py -> buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscanrobust_single_linkage_.py -> buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscanvalidity.py -> buildlib.win-amd64-cpython-39hdbscan
>           copying hdbscan__init__.py -> buildlib.win-amd64-cpython-39hdbscan
>           creating buildlib.win-amd64-cpython-39hdbscantests
>           copying hdbscanteststest_flat.py -> buildlib.win-amd64-cpython-39hdbscantests
>           copying hdbscanteststest_hdbscan.py -> buildlib.win-amd64-cpython-39hdbscantests
>           copying hdbscanteststest_prediction_utils.py -> buildlib.win-amd64-cpython-39hdbscantests
>           copying hdbscanteststest_rsl.py -> buildlib.win-amd64-cpython-39hdbscantests
>           copying hdbscantests__init__.py -> buildlib.win-amd64-cpython-39hdbscantests
>           running build_ext
>           cythoning hdbscan/_hdbscan_tree.pyx to hdbscan_hdbscan_tree.c
>           C:UsersMartin KunthAppDataLocalTemppip-build-env-a026odlfoverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-2r29izqwhdbscan_215c105aa4414866a73cfee4bf64c07ahdbscan_hdbscan_tree.pyx
>             tree = Parsing.p_module(s, pxd, full_module_name)
>           cythoning hdbscan/_hdbscan_linkage.pyx to hdbscan_hdbscan_linkage.c
>           C:UsersMartin KunthAppDataLocalTemppip-build-env-a026odlfoverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-2r29izqwhdbscan_215c105aa4414866a73cfee4bf64c07ahdbscan_hdbscan_linkage.pyx
>             tree = Parsing.p_module(s, pxd, full_module_name)
>           cythoning hdbscan/_hdbscan_boruvka.pyx to hdbscan_hdbscan_boruvka.c
>           C:UsersMartin KunthAppDataLocalTemppip-build-env-a026odlfoverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-2r29izqwhdbscan_215c105aa4414866a73cfee4bf64c07ahdbscan_hdbscan_boruvka.pyx
>             tree = Parsing.p_module(s, pxd, full_module_name)
>           cythoning hdbscan/_hdbscan_reachability.pyx to hdbscan_hdbscan_reachability.c
>           C:UsersMartin KunthAppDataLocalTemppip-build-env-a026odlfoverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-2r29izqwhdbscan_215c105aa4414866a73cfee4bf64c07ahdbscan_hdbscan_reachability.pyx
>             tree = Parsing.p_module(s, pxd, full_module_name)
>           cythoning hdbscan/_prediction_utils.pyx to hdbscan_prediction_utils.c
>           C:UsersMartin KunthAppDataLocalTemppip-build-env-a026odlfoverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-2r29izqwhdbscan_215c105aa4414866a73cfee4bf64c07ahdbscan_prediction_utils.pyx
>             tree = Parsing.p_module(s, pxd, full_module_name)
>           cythoning hdbscan/dist_metrics.pyx to hdbscandist_metrics.c
>           C:UsersMartin KunthAppDataLocalTemppip-build-env-a026odlfoverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-2r29izqwhdbscan_215c105aa4414866a73cfee4bf64c07ahdbscandist_metrics.pxd
>             tree = Parsing.p_module(s, pxd, full_module_name)
>           Using cached PyYAML-5.4.1-cp39-cp39-win_amd64.whl (213 kB)
>         Collecting sentence-transformers>=0.4.1
>           Using cached sentence_transformers-2.2.2-py3-none-any.whl
>         Requirement already satisfied: scipy>=1.0 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan>=0.8.28->bertopic)
> (1.7.1)
>         Requirement already satisfied: cython>=0.27 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan>=0.8.28->bertopic)
> (0.29.28)
>         Requirement already satisfied: joblib>=1.0 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan>=0.8.28->bertopic)
> (1.1.0)
>         Requirement already satisfied: python-dateutil>=2.7.3 in c:usersmartin kunthanaconda3libsite-packages (from
> pandas>=1.1.5->bertopic) (2.8.2)
>         Requirement already satisfied: pytz>=2017.3 in c:usersmartin kunthanaconda3libsite-packages (from pandas>=1.1.5->bertopic)
> (2021.3)
>         Collecting tenacity>=6.2.0
>           Using cached tenacity-8.0.1-py3-none-any.whl (24 kB)
>         Requirement already satisfied: threadpoolctl>=2.0.0 in c:usersmartin kunthanaconda3libsite-packages (from
> scikit-learn>=0.22.2.post1->bertopic) (2.2.0)
>         Collecting torch>=1.6.0
>           Using cached torch-1.12.0-cp39-cp39-win_amd64.whl (161.8 MB)
>         Collecting sentencepiece
>           Using cached sentencepiece-0.1.96-cp39-cp39-win_amd64.whl (1.1 MB)
>         Requirement already satisfied: nltk in c:usersmartin kunthanaconda3libsite-packages (from
> sentence-transformers>=0.4.1->bertopic) (3.6.5)
>         Collecting torchvision
>           Using cached torchvision-0.13.0-cp39-cp39-win_amd64.whl (1.1 MB)
>         Collecting transformers<5.0.0,>=4.6.0
>           Using cached transformers-4.21.0-py3-none-any.whl (4.7 MB)
>         Collecting huggingface-hub>=0.4.0
>           Using cached huggingface_hub-0.8.1-py3-none-any.whl (101 kB)
>         Requirement already satisfied: colorama in c:usersmartin kunthanaconda3libsite-packages (from tqdm>=4.41.1->bertopic)
> (0.4.4)
>         Collecting pynndescent>=0.5
>           Using cached pynndescent-0.5.7-py3-none-any.whl
>         Requirement already satisfied: numba>=0.49 in c:usersmartin kunthanaconda3libsite-packages (from umap-learn>=0.5.0->bertopic)
> (0.54.1)
>         Requirement already satisfied: filelock in c:usersmartin kunthanaconda3libsite-packages (from
> huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (3.3.1)
>         Requirement already satisfied: typing-extensions>=3.7.4.3 in c:usersmartin kunthanaconda3libsite-packages (from
> huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (3.10.0.2)
>         Requirement already satisfied: requests in c:usersmartin kunthanaconda3libsite-packages (from
> huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (2.27.1)
>         Requirement already satisfied: packaging>=20.9 in c:usersmartin kunthanaconda3libsite-packages (from
> huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic) (21.0)
>         Requirement already satisfied: setuptools in c:usersmartin kunthanaconda3libsite-packages (from
> numba>=0.49->umap-learn>=0.5.0->bertopic) (58.0.4)
>         Requirement already satisfied: llvmlite<0.38,>=0.37.0rc1 in c:usersmartin kunthanaconda3libsite-packages (from
> numba>=0.49->umap-learn>=0.5.0->bertopic) (0.37.0)
>         Requirement already satisfied: six>=1.5 in c:usersmartin kunthanaconda3libsite-packages (from
> python-dateutil>=2.7.3->pandas>=1.1.5->bertopic) (1.16.0)
>         Requirement already satisfied: regex!=2019.12.17 in c:usersmartin kunthanaconda3libsite-packages (from
> transformers<5.0.0,>=4.6.0->sentence-transformers>=0.4.1->bertopic)
> (2021.8.3)
>         Collecting tokenizers!=0.11.3,<0.13,>=0.11.1
>           Using cached tokenizers-0.12.1-cp39-cp39-win_amd64.whl (3.3 MB)
>         Requirement already satisfied: click in c:usersmartin kunthanaconda3libsite-packages (from
> nltk->sentence-transformers>=0.4.1->bertopic) (7.1.2)
>         Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in c:usersmartin kunthanaconda3libsite-packages (from
> torchvision->sentence-transformers>=0.4.1->bertopic) (8.4.0)
>         Requirement already satisfied: pyparsing>=2.0.2 in c:usersmartin kunthanaconda3libsite-packages (from
> packaging>=20.9->huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic) (3.0.4)
>         Requirement already satisfied: charset-normalizer~=2.0.0 in c:usersmartin kunthanaconda3libsite-packages (from
> requests->huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (2.0.4)
>         Requirement already satisfied: certifi>=2017.4.17 in c:usersmartin kunthanaconda3libsite-packages (from
> requests->huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (2021.10.8)
>         Requirement already satisfied: idna<4,>=2.5 in c:usersmartin kunthanaconda3libsite-packages (from
> requests->huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (3.2)
>         Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:usersmartin kunthanaconda3libsite-packages (from
> requests->huggingface-hub>=0.4.0->sentence-transformers>=0.4.1->bertopic)
> (1.26.7)
>         Building wheels for collected packages: hdbscan
>           Building wheel for hdbscan (pyproject.toml): started
>           Building wheel for hdbscan (pyproject.toml): finished with status 'error'
>         Failed to build hdbscan
>           building 'hdbscan._hdbscan_tree' extension
>           error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":
> https://visualstudio.microsoft.com/visual-cpp-build-tools/
>           [end of output]
>           
>           note: This error originates from a subprocess, and is likely not a problem with pip.
>           ERROR: Failed building wheel for hdbscan
>         ERROR: Could not build wheels for hdbscan, which is required to install pyproject.toml-based projects

我安装了 Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.32.31332。我也升级了我的点子 pip-22.2.1

我尝试安装 hdbscan 也遇到了错误:

pip install hdbscan

> Collecting hdbscan
>       Using cached hdbscan-0.8.28.tar.gz (5.2 MB)
>       Installing build dependencies: started
>       Installing build dependencies: finished with status 'done'
>       Getting requirements to build wheel: started
>       Getting requirements to build wheel: finished with status 'done'
>       Preparing metadata (pyproject.toml): started
>       Preparing metadata (pyproject.toml): finished with status 'done'
>     Requirement already satisfied: scikit-learn>=0.20 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan)
> (0.24.2)
>     Requirement already satisfied: joblib>=1.0 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan) (1.1.0)
>     Requirement already satisfied: scipy>=1.0 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan) (1.7.1)
>     Requirement already satisfied: numpy>=1.20 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan) (1.20.3)
>     Requirement already satisfied: cython>=0.27 in c:usersmartin kunthanaconda3libsite-packages (from hdbscan) (0.29.28)
>     Requirement already satisfied: threadpoolctl>=2.0.0 in c:usersmartin kunthanaconda3libsite-packages (from
> scikit-learn>=0.20->hdbscan) (2.2.0)
>     Building wheels for collected packages: hdbscan
>       Building wheel for hdbscan (pyproject.toml): started
>       Building wheel for hdbscan (pyproject.toml): finished with status 'error'
>     Failed to build hdbscan
>     Note: you may need to restart the kernel to use updated packages.
>       error: subprocess-exited-with-error
>       
>       Building wheel for hdbscan (pyproject.toml) did not run successfully.
>       exit code: 1
>       
>       [40 lines of output]
>       running bdist_wheel
>       running build
>       running build_py
>       creating build
>       creating buildlib.win-amd64-cpython-39
>       creating buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscanflat.py -> buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscanhdbscan_.py -> buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscanplots.py -> buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscanprediction.py -> buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscanrobust_single_linkage_.py -> buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscanvalidity.py -> buildlib.win-amd64-cpython-39hdbscan
>       copying hdbscan__init__.py -> buildlib.win-amd64-cpython-39hdbscan
>       creating buildlib.win-amd64-cpython-39hdbscantests
>       copying hdbscanteststest_flat.py -> buildlib.win-amd64-cpython-39hdbscantests
>       copying hdbscanteststest_hdbscan.py -> buildlib.win-amd64-cpython-39hdbscantests
>       copying hdbscanteststest_prediction_utils.py -> buildlib.win-amd64-cpython-39hdbscantests
>       copying hdbscanteststest_rsl.py -> buildlib.win-amd64-cpython-39hdbscantests
>       copying hdbscantests__init__.py -> buildlib.win-amd64-cpython-39hdbscantests
>       running build_ext
>       cythoning hdbscan/_hdbscan_tree.pyx to hdbscan_hdbscan_tree.c
>       C:UsersMartin KunthAppDataLocalTemppip-build-env-cn18pe9moverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-k2_bwg0zhdbscan_9b50b30873a2465bb3156fb27111abf2hdbscan_hdbscan_tree.pyx
>         tree = Parsing.p_module(s, pxd, full_module_name)
>       cythoning hdbscan/_hdbscan_linkage.pyx to hdbscan_hdbscan_linkage.c
>       C:UsersMartin KunthAppDataLocalTemppip-build-env-cn18pe9moverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-k2_bwg0zhdbscan_9b50b30873a2465bb3156fb27111abf2hdbscan_hdbscan_linkage.pyx
>         tree = Parsing.p_module(s, pxd, full_module_name)
>       cythoning hdbscan/_hdbscan_boruvka.pyx to hdbscan_hdbscan_boruvka.c
>       C:UsersMartin KunthAppDataLocalTemppip-build-env-cn18pe9moverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-k2_bwg0zhdbscan_9b50b30873a2465bb3156fb27111abf2hdbscan_hdbscan_boruvka.pyx
>         tree = Parsing.p_module(s, pxd, full_module_name)
>       cythoning hdbscan/_hdbscan_reachability.pyx to hdbscan_hdbscan_reachability.c
>       C:UsersMartin KunthAppDataLocalTemppip-build-env-cn18pe9moverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-k2_bwg0zhdbscan_9b50b30873a2465bb3156fb27111abf2hdbscan_hdbscan_reachability.pyx
>         tree = Parsing.p_module(s, pxd, full_module_name)
>       cythoning hdbscan/_prediction_utils.pyx to hdbscan_prediction_utils.c
>       C:UsersMartin KunthAppDataLocalTemppip-build-env-cn18pe9moverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-k2_bwg0zhdbscan_9b50b30873a2465bb3156fb27111abf2hdbscan_prediction_utils.pyx
>         tree = Parsing.p_module(s, pxd, full_module_name)
>       cythoning hdbscan/dist_metrics.pyx to hdbscandist_metrics.c
>       C:UsersMartin KunthAppDataLocalTemppip-build-env-cn18pe9moverlayLibsite-packagesCythonCompilerMain.py:369:
> FutureWarning: Cython directive 'language_level' not set, using 2 for
> now (Py2). This will change in a later release! File: C:UsersMartin
> KunthAppDataLocalTemppip-install-k2_bwg0zhdbscan_9b50b30873a2465bb3156fb27111abf2hdbscandist_metrics.pxd
>         tree = Parsing.p_module(s, pxd, full_module_name)
>       building 'hdbscan._hdbscan_tree' extension
>       error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":
> https://visualstudio.microsoft.com/visual-cpp-build-tools/
>       [end of output]
>       
>       note: This error originates from a subprocess, and is likely not a problem with pip.
>       ERROR: Failed building wheel for hdbscan
>     ERROR: Could not build wheels for hdbscan, which is required to install pyproject.toml-based projects

我现在不知道如何进行。任何帮助,将不胜感激。非常感谢。

stack overflow How to resolve ERROR: Could not build wheels for hdbscan, which is required to install pyproject.toml-based projects
原文答案

答案:

作者头像

你可以通过安装 python-dev 来解决这个问题

python3 -m pip install python-dev-tools --user --upgrade

另外,尝试使用 conda install 而不是 pip

conda install -c conda-forge hdbscan

此外,请确保安装 Microsoft Visual C++

作者头像

只是想让您知道 top2vec 可以给您同样的错误,因为它依赖于 hdbscan

相关问题