在Mac上使用pip install出现以下错误:error: command 'gcc' failed with exit status 1。

5

我尝试使用以下命令从PyPI安装软件包:

sudo pip3 install switcheo

但是最终安装程序失败了。
Error checking for conflicts.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2584, in version
return self._version
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2691, in __getattr__
raise AttributeError(attr)
AttributeError: _version

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 503, in _warn_about_conflicts
package_set, _dep_info = check_install_conflicts(to_install)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 108, in check_install_conflicts
package_set, _ = create_package_set_from_installed()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 47, in create_package_set_from_installed
package_set[name] = PackageDetails(dist.version, dist.requires())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2589, in version
raise ValueError(tmpl % self.PKG_INFO, self)
ValueError: ("Missing 'Version:' header and/or METADATA file", Unknown [unknown version] (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages))
Installing collected packages: scrypt, neocore, switcheo

scrypt-1.2.1/libcperciva/crypto/crypto_aes.c:6:10: fatal error: 'openssl/aes.h' file not found
#include <openssl/aes.h>
         ^~~~~~~~~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-b6w97vc0/scrypt/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-qvammwag/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-b6w97vc0/scrypt/

这是在运行pip安装命令后终端的完整输出结果。 我发现有一些针对Linux系统的解决方案,但对于Mac用户来说这里的帖子并不多。


请始终发布“完整的错误消息”。 - ForceBru
你尝试过在虚拟环境中安装吗? - deosha
好的,我已经更新了帖子并附上了其余的错误信息,但是我省略了终端输出的其余部分,因为它太多了。 - David
基本上,您的系统中不存在文件 openssl/aes.h,这意味着您应该安装一个名为 OpenSSL 的库。 - ForceBru
错误为致命错误:未找到'openssl/aes.h'文件。类似于Mac上未找到openssl-aes-h文件 - Keldorn
3个回答

15

在安装一个依赖于MacOS虚拟环境中的openssl库的其他库时,我遇到了这个问题一段时间。

由于Mac已将openssl弃用,转而使用自己的SSL。所以你需要做的是:

    brew install openssl

或者如果它已经安装好了,

    brew reinstall openssl

现在您需要更改LD和CPP标志。参考openssl重新安装对话框。应该会告诉您命令的位置!

openssl是"keg-only",这意味着它没有被符号链接到/usr/local中, 因为苹果已弃用OpenSSL,而是推荐使用自己的TLS和加密库。

如果您需要首先运行openssl,请将其添加到您的PATH中:

    echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

编译器可能需要设置才能找到openssl:

    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"

为了让pkg-config找到openssl,您可能需要设置:

    export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

1
太棒了,感谢回复。我之前发了一个类似的问题的帖子,但仍然没有明确的解决方案。这个看起来可以解决问题。 - David
太好了!我也花了一段时间才弄明白。 - Moonero

0

你可能缺少OpenSSL软件包,或者你的系统找不到它在哪里。尝试使用brew install openssl命令安装。

更详细的答案请参考Mac上找不到'openssl/aes.h'文件


0

花了几个小时,我终于成功安装了。

  • 如果您使用的是Mac并且使用Anaconda

  • 请从Anaconda打开Python终端

  • 然后粘贴以下链接并点击Enter。

  • conda install -c conda-forge/label/gcc7 wordcloud

  • 如果您需要更多的明确信息,请访问以下链接 https://anaconda.org/conda-forge/wordcloud


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