在Python3.5中安装hashlib失败 - 错误代码1

3

我正在尝试在我的Mac上安装hashlibpip不起作用,easy_install也不起作用。 以下是错误信息:

  Collecting hashlib
    Using cached hashlib-20081119.zip
      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.5/lib/python3.5/site-packages/setuptools/__init__.py", line 12, in <module>
    import setuptools.version
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/version.py", line 1, in <module>
    import pkg_resources
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 36, in <module>
    import email.parser
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/feedparser.py", line 27, in <module>
    from email import message
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/message.py", line 16, in <module>
    from email import utils
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/utils.py", line 28, in <module>
    import random
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 45, in <module>
    from hashlib import sha512 as _sha512
  File "/private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/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/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/ 

任何进一步的建议都将是很好的。提前感谢!

5
hashlib是Python标准库的一部分,无需安装即可使用。 - Klaus D.
但是,当我尝试使用库中的任何函数时,它会给出一个错误,说“AttributeError: 'builtin_function_or_method'对象没有属性'update'”(在使用update函数的情况下)。 - JC1
2
请提供原始错误信息(包括您的代码和适当的描述),而不是解决问题的方法。 - Klaus D.
2个回答

2
我知道这个问题很老,但我刚刚在谷歌上偶然发现了它,因为我遇到了同样的问题。在我的情况下,我正在使用AWS Elastic Beanstalk,并且我的环境收到了关于hashlib内部语法错误的同样晦涩错误消息。
对于AWS,诀窍不是将所有导入项都包含在requirements.txt文件中,而只包括您通常必须pip install的项目。这包括像hashlib、string和random等模块。
所以对于其他遇到这个问题的人:没有必要安装hashlib,只需导入它即可!

-1

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