使用pip3安装hashlib时出现不支持的哈希类型错误。

11

我正在尝试为Python 3.6.0安装hashlib库。使用pip3:

pip3 install hashlib

I get:

Collecting hashlib
  Downloading hashlib-20081119.zip (42kB)
  100% |████████████████████████████████| 51kB 1.6MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/__init__.py", line 10, in <module>
        from setuptools.extern.six.moves import filter, filterfalse, map
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/extern/__init__.py", line 1, in <module>
        from pkg_resources.extern import VendorImporter
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 36, in <module>
        import email.parser
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/parser.py", line 12, in <module>
        from email.feedparser import FeedParser, BytesFeedParser
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/feedparser.py", line 27, in <module>
        from email._policybase import compat32
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/_policybase.py", line 9, in <module>
        from email.utils import _has_surrogates
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/utils.py", line 28, in <module>
        import random
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 46, in <module>
        from hashlib import sha512 as _sha512
      File "/private/var/folders/3m/q2pmrqbd2l9154yp_9ww5rjm0000gn/T/pip-build-1upkmzey/hashlib/hashlib.py", line 80
        raise ValueError, "unsupported hash type"
                        ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3m/q2pmrqbd2l9154yp_9ww5rjm0000gn/T/pip-build-1upkmzey/hashlib/

你有没有任何想法如何解决这个问题?我目前使用的是macOS Sierra 10.12.6,使用pip3 9.0.1和python 3.6。


6
hashlib 模块已默认安装。无需安装,因为您可以看到它具有 python 2.* 编码语法。 - Bijoy
@Bijoy 我遇到了同样的问题。hashlib默认已经包含,我可以使用import hashlib。但是我无法使用from hashlib import blake2b。 我知道我的代码在另外两个环境中可以运行,但是当我尝试在一个新的干净环境中运行它时,出现了这个错误。 到目前为止,我已经通过pip3 install --upgrade pip升级了pip,然后尝试安装hashlib,但是失败了,并出现了与OP相同的错误。 我记得我必须从pip中安装hashlib模块,因为我的发行版中自带的版本没有这个算法...或者我应该使用其他算法?'BLAKE2b512','BLAKE2s256'? - Stéphane
@Bijoy:我的pip安装似乎没问题,因为我可以安装其他库,比如paramiko。 - Stéphane
1个回答

13

正如Bijoy指出的那样,无需下载hashlib模块,因为它已默认安装。

只需使用import hashlib即可使用它。


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