安装fasttext遇ModuleNotFoundError: No module named 'pybind11'问题求助
解决fasttext安装失败问题
问题描述
执行命令 python -m pip install -U fasttext 时安装失败,错误输出如下:
Collecting fasttext Using cached fasttext-0.9.2.tar.gz (68 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [25 lines of output] C:\Users\dorag\user\ドキュメント\仮想環境\64env\Scripts\python.exe: No module named pip Traceback (most recent call last): File "<string>", line 38, in __init__ ModuleNotFoundError: No module named 'pybind11' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\dorag\user\ドキュメント\仮想環境\64env\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\Users\dorag\user\ドキュメント\仮想環境\64env\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "C:\Users\dorag\user\ドキュメント\仮想環境\64env\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-de_xqg63\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-de_xqg63\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires self.run_setup() File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-de_xqg63\overlay\Lib\site-packages\setuptools\build_meta.py", line 480, in run_setup super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script) File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-de_xqg63\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup exec(code, locals()) File "<string>", line 72, in <module> File "<string>", line 41, in __init__ RuntimeError: pybind11 install failed. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
当前虚拟环境已安装的包(python -m pip freeze 输出):
annotated-types==0.6.0 attrs==23.1.0 beautifulsoup4==4.12.2 bleach==6.1.0 blis==0.7.11 bs4==0.0.1 cachetools==5.3.2 catalogue==2.0.10 certifi==2023.7.22 chardet==3.0.4 charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 confection==0.1.3 cymem==2.0.8 DateTime==5.2 decorator==5.1.1 defusedxml==0.7.1 entrypoints==0.4 et-xmlfile==1.1.0 fastjsonschema==2.18.1 filelock==3.13.1 files==1.1.1 fsspec==2023.10.0 gensim==4.3.2 ginza==5.1.3 ginza-transformers==0.4.2 huggingface-hub==0.17.3 idna==2.8 ipython-genutils==0.2.0 ja-ginza==5.1.3 ja-ginza-electra==5.1.3 Jinja2==3.1.2 joblib==1.2.0 jupyter_core==5.5.0 jupyterlab-pygments==0.2.2 langcodes==3.3.0 logzero==1.7.0 MarkupSafe==2.1.3 mecab==0.996.3 mistune==3.0.2 mpmath==1.3.0 murmurhash==1.0.10 nest-asyncio==1.5.8 networkx==3.2.1 numpy==1.25.0 openpyxl==3.1.2 packaging==23.2 pandas==2.1.2 pandocfilters==1.5.0 pathy==0.10.3 pickleshare==0.7.5 plac==1.4.1 platformdirs==4.0.0 portpicker==1.2.0 preshed==3.0.9 prompt-toolkit==1.0.18 pyasn1==0.5.0 pyasn1-modules==0.3.0 pybind11==2.11.1 pydantic==2.4.2 pydantic_core==2.10.1 Pygments==2.16.1 python-dateutil==2.8.2 pytz==2023.3.post1 pywin32==306 PyYAML==6.0.1 pyzmq==25.1.1 referencing==0.30.2 regex==2023.10.3 requests==2.21.0 rpds-py==0.12.0 rsa==4.9 scikit-learn==1.2.2 scipy==1.10.1 simple-mecab==1.2.1 simplegeneric==0.8.1 six==1.12.0 smart-open==6.4.0 soupsieve==2.5 spacy==3.6.1 spacy-alignments==0.9.1 spacy-legacy==3.0.12 spacy-loggers==1.0.5 spacy-transformers==1.1.9 srsly==2.4.8 SudachiDict-core==20230927 SudachiDict-full==20230927 SudachiPy==0.6.7 SudachiTra==0.1.8 sympy==1.12 thinc==8.1.12 threadpoolctl==3.1.0 tinycss2==1.2.1 tokenizers==0.13.3 torch==2.1.0 tornado==4.5.3 tqdm==4.66.1 traitlets==5.13.0 transformers==4.25.1 typer==0.9.0 typing_extensions==4.8.0 tzdata==2023.3 urllib3==1.24.3 wasabi==1.1.2 wcwidth==0.2.9 webencodings==0.5.1 zope.interface==6.1
解决方案
1. 修复虚拟环境的pip问题
错误提示虚拟环境内的Python找不到pip,先执行以下步骤修复:
- 激活虚拟环境:
.\64env\Scripts\activate - 重新安装并升级pip:
python -m ensurepip --upgrade
2. 解决fasttext编译依赖问题
虽然已安装pybind11,但Windows下编译fasttext常出现依赖识别异常,推荐直接使用预编译的wheel包安装:
- 执行
python --version确认你的Python版本(如3.10.x),并确认系统为64位 - 下载匹配Python版本和系统的fasttext wheel包
- 执行本地安装命令(替换为你的wheel包路径):
pip install path\to\fasttext-0.9.2-cp310-cp310-win_amd64.whl
如果坚持源码编译,需先安装Visual Studio Build Tools(勾选"C++ build tools"组件),再执行:
pip install -U fasttext
内容的提问来源于stack exchange,提问作者namba
相关产品推荐
相关产品推荐

