Failed to build fasttext

安装pip3 install hanlp报错:

Building wheels for collected packages: fasttext
Building wheel for fasttext (setup.py) … error
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.6 -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/private/tmp/pip-install-buiqhcep/fasttext/setup.py’"’"’; file=’"’"’/private/tmp/pip-install-buiqhcep/fasttext/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ bdist_wheel -d /private/tmp/pip-wheel-u9_fpgjn --python-tag cp36
cwd: /private/tmp/pip-install-buiqhcep/fasttext/
Complete output (33 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.13-x86_64-3.6
creating build/lib.macosx-10.13-x86_64-3.6/fasttext
copying python/fasttext_module/fasttext/init.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext
copying python/fasttext_module/fasttext/FastText.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext
creating build/lib.macosx-10.13-x86_64-3.6/fasttext/util
copying python/fasttext_module/fasttext/util/util.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/util
copying python/fasttext_module/fasttext/util/init.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/util
creating build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
copying python/fasttext_module/fasttext/tests/test_script.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
copying python/fasttext_module/fasttext/tests/init.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
copying python/fasttext_module/fasttext/tests/test_configurations.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
running build_ext
creating tmp
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c /tmp/tmp3wsh6kc5.cpp -o tmp/tmp3wsh6kc5.o -stdlib=libc++
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c /tmp/tmpm2z68xvv.cpp -o tmp/tmpm2z68xvv.o -std=c++14
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c /tmp/tmp2m9sktxx.cpp -o tmp/tmp2m9sktxx.o -fvisibility=hidden
building ‘fasttext_pybind’ extension
creating build/temp.macosx-10.13-x86_64-3.6
creating build/temp.macosx-10.13-x86_64-3.6/python
creating build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module
creating build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module/fasttext
creating build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module/fasttext/pybind
creating build/temp.macosx-10.13-x86_64-3.6/src
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include/python3.6m -I/Users/jerry/Library/Python/3.6/include/python3.6m -Isrc -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c python/fasttext_module/fasttext/pybind/fasttext_pybind.cc -o build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module/fasttext/pybind/fasttext_pybind.o -stdlib=libc++ -DVERSION_INFO=“0.9.1” -std=c++14 -fvisibility=hidden
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc:12:10: fatal error: ‘pybind11/pybind11.h’ file not found
#include <pybind11/pybind11.h>
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
error: command ‘clang’ failed with exit status 1

ERROR: Failed building wheel for fasttext
Running setup.py clean for fasttext
Failed to build fasttext
Installing collected packages: py-params, tqdm, params-flow, bert-for-tf2, fasttext, hanlp
Running setup.py install for fasttext … error
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.6 -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/private/tmp/pip-install-buiqhcep/fasttext/setup.py’"’"’; file=’"’"’/private/tmp/pip-install-buiqhcep/fasttext/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record /private/tmp/pip-record-zo4f77vf/install-record.txt --single-version-externally-managed --compile
cwd: /private/tmp/pip-install-buiqhcep/fasttext/
Complete output (32 lines):
running install
running build
running build_py
creating build
creating build/lib.macosx-10.13-x86_64-3.6
creating build/lib.macosx-10.13-x86_64-3.6/fasttext
copying python/fasttext_module/fasttext/init.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext
copying python/fasttext_module/fasttext/FastText.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext
creating build/lib.macosx-10.13-x86_64-3.6/fasttext/util
copying python/fasttext_module/fasttext/util/util.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/util
copying python/fasttext_module/fasttext/util/init.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/util
creating build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
copying python/fasttext_module/fasttext/tests/test_script.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
copying python/fasttext_module/fasttext/tests/init.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
copying python/fasttext_module/fasttext/tests/test_configurations.py -> build/lib.macosx-10.13-x86_64-3.6/fasttext/tests
running build_ext
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c /tmp/tmpb6inudso.cpp -o tmp/tmpb6inudso.o -stdlib=libc++
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c /tmp/tmpfacrwml4.cpp -o tmp/tmpfacrwml4.o -std=c++14
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c /tmp/tmpeybkt9c4.cpp -o tmp/tmpeybkt9c4.o -fvisibility=hidden
building ‘fasttext_pybind’ extension
creating build/temp.macosx-10.13-x86_64-3.6
creating build/temp.macosx-10.13-x86_64-3.6/python
creating build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module
creating build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module/fasttext
creating build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module/fasttext/pybind
creating build/temp.macosx-10.13-x86_64-3.6/src
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include/python3.6m -I/Users/jerry/Library/Python/3.6/include/python3.6m -Isrc -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c python/fasttext_module/fasttext/pybind/fasttext_pybind.cc -o build/temp.macosx-10.13-x86_64-3.6/python/fasttext_module/fasttext/pybind/fasttext_pybind.o -stdlib=libc++ -DVERSION_INFO=“0.9.1” -std=c++14 -fvisibility=hidden
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc:12:10: fatal error: ‘pybind11/pybind11.h’ file not found
#include <pybind11/pybind11.h>
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
error: command ‘clang’ failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.6 -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/private/tmp/pip-install-buiqhcep/fasttext/setup.py’"’"’; file=’"’"’/private/tmp/pip-install-buiqhcep/fasttext/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record /private/tmp/pip-record-zo4f77vf/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

mac环境

hello,请问你最后解决了吗,我也遇到了这个问题

fasttext的安装需要一些依赖包的,建议谷歌一下吧,stackoverflow上面有很多解决方法的,并且是针对macos的

来源:https://github.com/salestock/fastText.py/issues/91#issuecomment-342117954

My OS is Windows 8.1 64bit, Python 3.6.3, I have downloaded “Visual C++ 2015 Build Tools” using following link and I have installed it, after that fasttext installation worked properly.
Good luck
http://go.microsoft.com/fwlink/?LinkId=691126&__hstc=268264337.8504ec8bdb50032c9b5af147b6b0ef56.1509965482729.1509965482729.1509965482729.1&__hssc=268264337.4.1509965482730&__hsfp=2646871122&fixForIE=.exe

1 Like

升级 gcc编译器就好了吧。
fasttext 官网

Generally, fastText builds on modern Mac OS and Linux distributions. Since it uses some C++11 features, it requires a compiler with good C++11 support. These include :

  • (g+±4.7.2 or newer) or (clang-3.3 or newer)

windows10 环境可以参考

Centos环境 yum install gcc-c++
windown环境 搜索安装VC_redist.x64.exe

1 Like