本文介绍了Python/Flask 错误:“导入错误:无法导入名称 _compare_digest";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Windows,我正在关注 这个 Flask 教程 当我遇到以下错误时:

With Windows, I am following this Flask tutorial when I came across the following error:

C:UsersGregory GundersenDocumentsResearchflask-test>python run.py
Traceback (most recent call last):
  File "run.py", line 2, in <module>
    from app import app
  File "C:UsersGregory GundersenDocumentsResearchflask-testapp\__init__.py
", line 1, in <module>
    from flask import Flask
  File "C:Python27libsite-packagesflask\__init__.py", line 21, in <module>
    from .app import Flask, Request, Response
  File "C:Python27libsite-packagesflaskapp.py", line 26, in <module>
    from . import json
  File "C:Python27libsite-packagesflaskjson.py", line 25, in <module>
    from itsdangerous import json as _json
  File "C:Python27libsite-packagesitsdangerous.py", line 14, in <module>
    import hmac
  File "C:Python27libhmac.py", line 8, in <module>
    from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest

SO 问题和答案,但它们是为了OS X/Django.有没有人在 PC/Flask 上看到或解决过这个问题?

There are SO questions and answers, but they are for OS X/Django. Has anyone see or resolved this issue for PC/Flask before?

推荐答案

您似乎对 一半的更改>issue 21306(将 hmac.compare_digest 反向移植到 2.7).

You appear to have half the changes made for issue 21306 (backporting hmac.compare_digest to 2.7).

你的 hmac 模块有以下几行:

Your hmac module has the lines:

from operator import _compare_digest as compare_digest

在顶部,但您的 sys.version_info 显示您正在运行 Python 2.7.6;引用我们的快速聊天会话:

at the top, but your sys.version_info shows you are running Python 2.7.6; quoting our quick chat session:

我:下一个简单的检查:

import sys
print(sys.version_info)

您:sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)

您拥有的 hmac 版本适用于 Python 2.7.7 及以上,但是!

The hmac version you have is for Python 2.7.7 and up, however!

您需要重新安装 Python;下载 2.7.8 并重新安装,以确保您的标准库文件具有正确的二进制可执行文件.

You'll want to reinstall your Python; download 2.7.8 and reinstall it to make sure you have the correct binary executable for your standard library files.

这篇关于Python/Flask 错误:“导入错误:无法导入名称 _compare_digest";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:44