在 python 3.7 中安装 "hmac" 软件包时出错

error installing while "hmac" package in python 3.7

当我安装 HMAC 包时使用 pip 安装 hmac 基础环境中的命令

我尝试更新 pip、设置工具。但都更新到最新版本。但是没用。

pip 安装 hmac

错误:

C:\WINDOWS\system32>pip install hmac
Collecting hmac
  Using cached https://files.pythonhosted.org/packages/b2/02/14b2ade413d3f34caffadfa6ed59f3769fe108a78e34931a2cdd1762cb32/hmac-20101005.tar.gz
Requirement already satisfied: setuptools in c:\programdata\anaconda3\lib\site-packages (from hmac) (41.4.0)
Collecting hashlib
  Using cached https://files.pythonhosted.org/packages/74/bb/9003d081345e9f0451884146e9ea2cff6e4cc4deac9ffd4a9ee98b318a49/hashlib-20081119.zip
    ERROR: Command errored out with exit status 1:
     command: 'c:\programdata\anaconda3\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Admin\AppData\Local\Temp\pip-install-7dt9idd0\hashlib\setup.py'"'"'; __file__='"'"'C:\Users\Admin\AppData\Local\Temp\pip-install-7dt9idd0\hashlib\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Admin\AppData\Local\Temp\pip-install-7dt9idd0\hashlib\pip-egg-info'
         cwd: C:\Users\Admin\AppData\Local\Temp\pip-install-7dt9idd0\hashlib\
    Complete output (22 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\programdata\anaconda3\lib\site-packages\setuptools\__init__.py", line 18, in <module>
        import setuptools.version
      File "c:\programdata\anaconda3\lib\site-packages\setuptools\version.py", line 1, in <module>
        import pkg_resources
      File "c:\programdata\anaconda3\lib\site-packages\pkg_resources\__init__.py", line 36, in <module>
        import email.parser
      File "c:\programdata\anaconda3\lib\email\parser.py", line 12, in <module>
        from email.feedparser import FeedParser, BytesFeedParser
      File "c:\programdata\anaconda3\lib\email\feedparser.py", line 27, in <module>
        from email._policybase import compat32
      File "c:\programdata\anaconda3\lib\email\_policybase.py", line 9, in <module>
        from email.utils import _has_surrogates
      File "c:\programdata\anaconda3\lib\email\utils.py", line 28, in <module>
        import random
      File "c:\programdata\anaconda3\lib\random.py", line 46, in <module>
        from hashlib import sha512 as _sha512
      File "C:\Users\Admin\AppData\Local\Temp\pip-install-7dt9idd0\hashlib\hashlib.py", line 80
        raise ValueError, "unsupported hash type"
                        ^
    SyntaxError: invalid syntax
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output

语法错误是因为报告的行 raise ValueError, "unsupported hash type" 使用了 python 3.x 不支持的语法,这引起了您正在尝试安装的模块的怀疑不是为 python 3.x 写的,而是为 2.x

写的

您尝试安装的模块是 this one

pypi 项目中唯一的文件来自 06.10.2010,差不多 9 年了,查看项目描述,我们得到:

HMAC

This is a stand alone packaging of the hashlib compatible hmac library included with Python 2.5 so that it can be used together with the hashlib backport on older versions of Python (tested on 2.4). Not needed with Python 2.5 or later.

所以确实,hmac 是在只考虑 python 2x 的情况下编写的,此后没有更新。您可能想寻找一个不同的库,或者只使用 python standard library 中的 hmac,不需要额外安装。