Mac利用pip安装allennlp包方法,及安装jsonnet时g++报错解决方法

mac系统利用pip安装allennlp包时,输入如下代码

pip install allennlp --user

然后运行到安装jsonnet包时发生错误

Building wheels for collected packages: jsonnet
  Building wheel for jsonnet (setup.py) ... error
  ERROR: Complete output from command /usr/local/anaconda3/envs/allennlp/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-install-5igclfl8/jsonnet/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/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-wheel-h870sk60 --python-tag cp36:
  ERROR: running bdist_wheel
  running build
  running build_ext
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/desugarer.cpp -o core/desugarer.o
  core/desugarer.cpp:406:67: warning: unused parameter 'obj_level' [-Wunused-parameter]
      AST* makeArrayComprehension(ArrayComprehension *ast, unsigned obj_level) {
                                                                    ^
  1 warning generated.
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/formatter.cpp -o core/formatter.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/libjsonnet.cpp -o core/libjsonnet.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/lexer.cpp -o core/lexer.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/parser.cpp -o core/parser.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/pass.cpp -o core/pass.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/static_analysis.cpp -o core/static_analysis.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/string_utils.cpp -o core/string_utils.o
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/vm.cpp -o core/vm.o
  core/vm.cpp:1337:21: warning: comparison of integers of different signs: 'int' and 'std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> >::size_type' (aka 'unsigned long') [-Wsign-compare]
          while (test < str->value.size() && (maxsplits == -1 ||
                 ~~~~ ^ ~~~~~~~~~~~~~~~~~
  core/vm.cpp:1338:55: warning: comparison of integers of different signs: 'long' and 'std::__1::vector<(anonymous namespace)::HeapThunk *, std::__1::allocator<(anonymous namespace)::HeapThunk *> >::size_type' (aka 'unsigned long') [-Wsign-compare]
                                              maxsplits > elements.size())) {
                                              ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
  core/vm.cpp:1362:24: warning: comparison of integers of different signs: 'long' and 'std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> >::size_type' (aka 'unsigned long') [-Wsign-compare]
          if (len + from > str->value.size()) {
              ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
  core/vm.cpp:1419:27: warning: comparison of integers of different signs: 'int' and 'std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> >::size_type' (aka 'unsigned long') [-Wsign-compare]
          for (int i = 0; i < new_str.size(); ++i) {
                          ~ ^ ~~~~~~~~~~~~~~
  core/vm.cpp:1433:27: warning: comparison of integers of different signs: 'int' and 'std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> >::size_type' (aka 'unsigned long') [-Wsign-compare]
          for (int i = 0; i < new_str.size(); ++i) {
                          ~ ^ ~~~~~~~~~~~~~~
  core/vm.cpp:1533:33: warning: comparison of integers of different signs: 'int' and 'std::__1::vector<(anonymous namespace)::HeapThunk *, std::__1::allocator<(anonymous namespace)::HeapThunk *> >::size_type' (aka 'unsigned long') [-Wsign-compare]
              for (int i = idx; i < elements.size(); ++i) {
                                ~ ^ ~~~~~~~~~~~~~~~
  core/vm.cpp:1577:33: warning: comparison of integers of different signs: 'int' and 'std::__1::vector<(anonymous namespace)::HeapThunk *, std::__1::allocator<(anonymous namespace)::HeapThunk *> >::size_type' (aka 'unsigned long') [-Wsign-compare]
              for (int i = idx; i < elements.size(); ++i) {
                                ~ ^ ~~~~~~~~~~~~~~~
  7 warnings generated.
  c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json third_party/md5/md5.cpp -o third_party/md5/md5.o
  building '_jsonnet' extension
  creating build
  creating build/temp.macosx-10.7-x86_64-3.6
  creating build/temp.macosx-10.7-x86_64-3.6/python
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/anaconda3/envs/allennlp/include -arch x86_64 -I/usr/local/anaconda3/envs/allennlp/include -arch x86_64 -Iinclude -Ithird_party/md5 -Ithird_party/json -I/usr/local/anaconda3/envs/allennlp/include/python3.6m -c python/_jsonnet.c -o build/temp.macosx-10.7-x86_64-3.6/python/_jsonnet.o
  python/_jsonnet.c:147:19: warning: comparison of integers of different signs: 'int' and 'const size_t' (aka 'const unsigned long') [-Wsign-compare]
      for (i = 0; i < ctx->argc; ++i) {
                  ~ ^ ~~~~~~~~~
  1 warning generated.
  creating build/lib.macosx-10.7-x86_64-3.6
  g++ -bundle -undefined dynamic_lookup -L/usr/local/anaconda3/envs/allennlp/lib -L/usr/local/anaconda3/envs/allennlp/lib -arch x86_64 build/temp.macosx-10.7-x86_64-3.6/python/_jsonnet.o core/desugarer.o core/formatter.o core/libjsonnet.o core/lexer.o core/parser.o core/pass.o core/static_analysis.o core/string_utils.o core/vm.o third_party/md5/md5.o -L/usr/local/anaconda3/envs/allennlp/lib -o build/lib.macosx-10.7-x86_64-3.6/_jsonnet.cpython-36m-darwin.so
  clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
  ld: library not found for -lstdc++
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'g++' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for jsonnet
  Running setup.py clean for jsonnet
Failed to build jsonnet
Installing collected packages: jsonnet, allennlp
  Running setup.py install for jsonnet ... error
    ERROR: Complete output from command /usr/local/anaconda3/envs/allennlp/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-install-5igclfl8/jsonnet/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/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-record-o4j69o6d/install-record.txt --single-version-externally-managed --compile --user --prefix=:
    ERROR: running install
    running build
    running build_ext
    make: `core/desugarer.o' is up to date.
    make: `core/formatter.o' is up to date.
    make: `core/libjsonnet.o' is up to date.
    make: `core/lexer.o' is up to date.
    make: `core/parser.o' is up to date.
    make: `core/pass.o' is up to date.
    make: `core/static_analysis.o' is up to date.
    make: `core/string_utils.o' is up to date.
    make: `core/vm.o' is up to date.
    make: `third_party/md5/md5.o' is up to date.
    building '_jsonnet' extension
    creating build
    creating build/temp.macosx-10.7-x86_64-3.6
    creating build/temp.macosx-10.7-x86_64-3.6/python
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/anaconda3/envs/allennlp/include -arch x86_64 -I/usr/local/anaconda3/envs/allennlp/include -arch x86_64 -Iinclude -Ithird_party/md5 -Ithird_party/json -I/usr/local/anaconda3/envs/allennlp/include/python3.6m -c python/_jsonnet.c -o build/temp.macosx-10.7-x86_64-3.6/python/_jsonnet.o
    python/_jsonnet.c:147:19: warning: comparison of integers of different signs: 'int' and 'const size_t' (aka 'const unsigned long') [-Wsign-compare]
        for (i = 0; i < ctx->argc; ++i) {
                    ~ ^ ~~~~~~~~~
    1 warning generated.
    creating build/lib.macosx-10.7-x86_64-3.6
    g++ -bundle -undefined dynamic_lookup -L/usr/local/anaconda3/envs/allennlp/lib -L/usr/local/anaconda3/envs/allennlp/lib -arch x86_64 build/temp.macosx-10.7-x86_64-3.6/python/_jsonnet.o core/desugarer.o core/formatter.o core/libjsonnet.o core/lexer.o core/parser.o core/pass.o core/static_analysis.o core/string_utils.o core/vm.o third_party/md5/md5.o -L/usr/local/anaconda3/envs/allennlp/lib -o build/lib.macosx-10.7-x86_64-3.6/_jsonnet.cpython-36m-darwin.so
    clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
    ld: library not found for -lstdc++
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'g++' failed with exit status 1
    ----------------------------------------
ERROR: Command "/usr/local/anaconda3/envs/allennlp/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-install-5igclfl8/jsonnet/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/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-record-o4j69o6d/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /private/var/folders/5z/pnhclkxj3fbd1gsyrr656m2w0000gn/T/pip-install-5igclfl8/jsonnet/

参考github上的相似问题:

https://github.com/allenai/allennlp/issues/2779

原因是,在linux系统下我们会使用g++进行编译,但是这里我们使用clang。然后mac OS Mojave的新版本的版本号在allennlp里面并没有更新。所以我们需要更新环境变量:

打开环境变量配置文件:

vim ~/.bash_profile

添加如下代码

export MACOSX_DEPLOYMENT_TARGET=10.14

保存并退出后会提示安装macOS_SDK_headers_for_macOS_10.14.pkg这个应用程序。按照提示安装好。

然后就,就解决了~

再试一次吧~~~

pip install jsonnet
pip install allennlp --user

成功啦!!

猜你喜欢

转载自blog.csdn.net/qq_22472047/article/details/107668633