在 MacOS 中安装 gcutil 时收到错误

Posted

技术标签:

【中文标题】在 MacOS 中安装 gcutil 时收到错误【英文标题】:Receive error when I installing gcutil in MacOS 【发布时间】:2019-12-01 12:42:39 【问题描述】:

我按照official documents 给出的指令执行了./install.sh

MacOS 版本:10.14.5 (18F132) Python版本:python2.7

下载gcloud网站提供的zip文件后,我运行命令./install.sh。它告诉我

weiziyangdeMacBook-Pro:google-cloud-sdk weiziyang$ ./install.sh
Welcome to the Google Cloud SDK!
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "/Users/weiziyang/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
    import bootstrapping
  File "/Users/weiziyang/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
    import setup  # pylint:disable=g-import-not-at-top
  File "/Users/weiziyang/google-cloud-sdk/bin/bootstrapping/setup.py", line 55, in <module>
    from googlecloudsdk.core import properties
  File "/Users/weiziyang/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 27, in <module>
    from googlecloudsdk.core import config
  File "/Users/weiziyang/google-cloud-sdk/lib/googlecloudsdk/core/config.py", line 29, in <module>
    from googlecloudsdk.core.util import files as file_utils
  File "/Users/weiziyang/google-cloud-sdk/lib/googlecloudsdk/core/util/files.py", line 600, in <module>
    class Checksum(object):
  File "/Users/weiziyang/google-cloud-sdk/lib/googlecloudsdk/core/util/files.py", line 603, in Checksum
    def __init__(self, algorithm=hashlib.sha256):
AttributeError: 'module' object has no attribute 'sha256'

我检查了python2的模块,它提供了我已经正确安装了hashlib并且具有属性'sha256'

weiziyangdeMacBook-Pro:google-cloud-sdk weiziyang$ python2
Python 2.7.10 (default, Feb 22 2019, 21:55:15) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> hashlib.sha256
<built-in function openssl_sha256>
>>> exit()

我希望它可以正确安装。

【问题讨论】:

【参考方案1】:

对我有用的是

    brew uninstallbrew list列出的所有openssl和python包

    brew install python3

    sudo ln -s /usr/local/bin/python3 /usr/local/bin/pythonsudo ln -s /usr/local/bin/pip3 /usr/local/bin/pip

    使用 Google Cloud SDK 安装程序安装 gcloud https://cloud.google.com/sdk/docs/downloads-interactive

【讨论】:

升级到 macOS Catalina 后遇到了同样的问题。上面的说明真的很有帮助!【参考方案2】:

这就是我所做的 转到/usr/local/Cellar/ 并删除除python@3.x.x 之外的所有python 文件夹,然后再次运行./install.sh 即可。

【讨论】:

【参考方案3】:

您在上述两个示例中使用的两个 Python 版本是不同的。您使用的第一个 Python 是 2.7.15:

File "/usr/local/Cellar/python@2/2.7.15/...

第二个是2.7.10:

Python 2.7.10 (default, Feb 22 2019, 21:55:15)

您的 Python 2.7.15 安装似乎没有正确安装 hashlib(这可能是由于安装期间的 OpenSSL 问题等原因造成的)。如果我不得不猜测,Cloud SDK install.sh 脚本会查找 python 可执行文件,python 可能指向损坏的 2.7.15 安装,而 python2 可能指向您系统上的 2.7.10 安装.

【讨论】:

【参考方案4】:

问题是由libssl 的冲突引起的。 所以,解决办法是:

ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

【讨论】:

这对我不起作用。仍在寻找解决方案。同时,Google Cloud SDK 在我的 Mac 上无法使用。我确实下载/提取了最新的 SDK,并在尝试运行“./google-cloud-sdk/install.sh”时收到“不支持的哈希类型”错误。

以上是关于在 MacOS 中安装 gcutil 时收到错误的主要内容,如果未能解决你的问题,请参考以下文章

在 PyCharm (macOS) 中安装 dlib 时出现问题

在 macOS 中安装 pyqt 的问题

在裸机反应本机项目中安装 expo 后,我收到此错误

如何使用 homebrew 在 MACOS 中安装 node.js

在 R studio 中安装 factoextra 包

在 TypeScript 中安装 jQuery 时出错