在conda/MacOS上使用pip安装mmh3包

4

我正在尝试在 MacOS 上安装一个需要 mmh3 的包。

但是当我开始安装时,我会遇到错误,对我来说这些错误就像是用一种不同的语言写出来的。

迄今为止的搜索让我相信,这可能与我机器上的 Apple xCode 版本有关,但我找到的答案都没有意义。如果我只是调用 pip install mmh3,我不知道如何编辑安装文件。

以下是输出结果,我知道它很长,但我不知道什么是相关的或者不相关的,所以我都贴出来了。这似乎与 Apple 重命名 c++ 或类似的内容有关。感激任何帮助。请记住我不知道为什么需要这个包,只知道它是必要的。

Collecting mmh3
  Using cached https://files.pythonhosted.org/packages/fa/7e/3ddcab0a9fcea034212c02eb411433db9330e34d626360b97333368b4052/mmh3-2.5.1.tar.gz
Building wheels for collected packages: mmh3
  Running setup.py bdist_wheel for mmh3 ... error
  Complete output from command /Users/ronan/miniconda3/envs/prodigy/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-install-qieyu8iz/mmh3/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/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-wheel-a0npl5pu --python-tag cp37:
  running bdist_wheel
  running build
  running build_ext
  building 'mmh3' extension
  creating build
  creating build/temp.macosx-10.7-x86_64-3.7
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include/python3.7m -c mmh3module.cpp -o build/temp.macosx-10.7-x86_64-3.7/mmh3module.o
  warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
  1 warning generated.
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include/python3.7m -c MurmurHash3.cpp -o build/temp.macosx-10.7-x86_64-3.7/MurmurHash3.o
  warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
  1 warning generated.
  creating build/lib.macosx-10.7-x86_64-3.7
  g++ -bundle -undefined dynamic_lookup -L/Users/ronan/miniconda3/envs/prodigy/lib -arch x86_64 -L/Users/ronan/miniconda3/envs/prodigy/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.7-x86_64-3.7/mmh3module.o build/temp.macosx-10.7-x86_64-3.7/MurmurHash3.o -o build/lib.macosx-10.7-x86_64-3.7/mmh3.cpython-37m-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

  ----------------------------------------
  Failed building wheel for mmh3
  Running setup.py clean for mmh3
Failed to build mmh3
Installing collected packages: mmh3
  Running setup.py install for mmh3 ... error
    Complete output from command /Users/ronan/miniconda3/envs/prodigy/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-install-qieyu8iz/mmh3/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/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-record-z9u9z7f5/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'mmh3' extension
    creating build
    creating build/temp.macosx-10.7-x86_64-3.7
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include/python3.7m -c mmh3module.cpp -o build/temp.macosx-10.7-x86_64-3.7/mmh3module.o
    warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include -arch x86_64 -I/Users/ronan/miniconda3/envs/prodigy/include/python3.7m -c MurmurHash3.cpp -o build/temp.macosx-10.7-x86_64-3.7/MurmurHash3.o
    warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    1 warning generated.
    creating build/lib.macosx-10.7-x86_64-3.7
    g++ -bundle -undefined dynamic_lookup -L/Users/ronan/miniconda3/envs/prodigy/lib -arch x86_64 -L/Users/ronan/miniconda3/envs/prodigy/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.7-x86_64-3.7/mmh3module.o build/temp.macosx-10.7-x86_64-3.7/MurmurHash3.o -o build/lib.macosx-10.7-x86_64-3.7/mmh3.cpython-37m-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

    ----------------------------------------
Command "/Users/ronan/miniconda3/envs/prodigy/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-install-qieyu8iz/mmh3/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/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-record-z9u9z7f5/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/29/638ydzz51zxfm1hht53r24w80000gn/T/pip-install-qieyu8iz/mmh3/

我知道这个问题以前已经被问过了(可能是我自己问的),关于这个软件包。我现在发现它已经在GitHub上被开发者标记了这里,但目前还没有得到回应。如果有人熟悉构建Python Wheels或者确切地说C++代码需要更新的位置,再次帮助将不胜感激。这是一个苹果操作系统的问题,导致了许多下游问题。像往常一样,@ines或honnibal,您的意见将不胜感激。 - rtob
实际上,当我执行“pip install mmh3”时,我得到了完全相同的错误消息。幸运的是,在尝试了一些方法后,我成功了。 => 我删除了旧的Python版本并安装了最新的Python3、虚拟环境、pip等。Clang或Xcode对我没有帮助,只有清洁的Python安装才能帮助我。 - JUNPA
2个回答

1
我按照链接https://anaconda.org/conda-forge/mmh3中的指南进行操作,发现它可以正常工作。
要使用conda安装此软件包,请运行以下命令之一:
conda install -c conda-forge mmh3
conda install -c conda-forge/label/cf202003 mmh3

这对我帮助很大!谢谢! - mztkenan

0

所以,一如既往,在你看到答案之后,它非常简单。

解决这个问题以及任何依赖于这些 C++ 库从 Python 引用的其他问题的解决方案是在实现包时使用的 setup.py 文件中的 if/else 块。如果在 OSX >= 10.7 上运行,则包含并执行以下代码行将解决 pip 和 Python 的此类投诉。

COMPILE_OPTIONS["other"].append("-stdlib=libc++")
LINK_OPTIONS["other"].append("-lc++")
LINK_OPTIONS["other"].append("-nodefaultlibs")

参考:此处有关于该问题来源的一些信息。

解决方案的信用应归功于 @honnibal,现在可以通过 此链接 获得完整的 if/else 逻辑和代码块,所以您可以查看一下其中的细节。


我执行了git clone,然后在setup.py文件上运行了pip install。我得到了这个错误:ld: "library not found for -lstdc++"。有什么想法吗? - David
你是否已经安装了苹果的开发套件?也就是xCode和相关库文件?这就是需要命令行工具的地方,也是问题产生的根源。如果你还没有安装或更新xCode和命令行工具,请考虑安装/更新。很抱歉我无法提供更多帮助! - rtob
谢谢rtob。我进行了更深入的挖掘,但似乎在OSX 10.7+上不再提供这些库。我还是卡住了:'( - David
你好,@David - 我不太确定如何最好地回应这个问题,因为我不再使用这个环境了。lstdc++ 库应该已经被干净地弃用了吧?如果没有,那么在从中构建 wheel 之前,可能需要更改 setup.py 文件中的一些小细节或 if/else 块。 - rtob

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