【问题标题】:ModuleNotFoundError: No module named '_crypt'ModuleNotFoundError:没有名为“_crypt”的模块
【发布时间】:2022-06-23 23:10:18
【问题描述】:

我正在尝试使用 Flask 并从第一个示例开始,同时运行以下代码

from crypt import methods
from flask import Flask

app = Flask(__name__)

@app.route('/', methods=['GET'])
def hello_world():
    return "Hello world"


if __name__=='__main__':
    app.run(port=3000, debug=True)

我收到以下错误

ModuleNotFoundError: No module named '_crypt'

During handling of the above exception, another exception occurred

The error

【问题讨论】:

  • 我已经尝试安装 crypt 模块但没有成功

标签: python windows crypt


【解决方案1】:

cryptUnix Specific Service,在 Windows 操作系统上不受支持。

就在docs 的顶部,用于crypt

34.5。 crypt — 检查 Unix 密码的函数

平台:Unix

替代方法是使用 passlib:

from passlib.hash import md5_crypt as md5
from passlib.hash import sha256_crypt as sha256
from passlib.hash import sha512_crypt as sha512

md5_passwd = md5.encrypt(passwd, rounds=5000, implicit_rounds=True)
sha256_passwd = sha256.encrypt(passwd, rounds=5000, implicit_rounds=True)
sha512_passwd = sha512.encrypt(passwd, rounds=5000, implicit_rounds=True)

【讨论】:

  • 你的意思是我必须将这些行添加到文件 crypt.py
  • 文件crypt.py的第一行: import sys as _sys try: import _crypt except ModuleNotFoundError: if _sys.platform == 'win32': raise ImportError("The crypt module is not supported on Windows") else: raise ImportError("所需的 _crypt 模块不是作为 CPython 的一部分构建的")
  • 我的意思是它是一个 Unix/Linux 操作系统包,在 windows 操作系统中不受支持。为此,我添加了一个替代方案。
  • 好的,谢谢你的帮助
【解决方案2】:

#from crypt 导入方法 从烧瓶进口烧瓶,请求

【讨论】:

    相关资源