ModuleNotFoundError: No module named 'captcha.image'; 'captcha' is not a package

ModuleNotFoundError: No module named 'captcha.image'; 'captcha' is not a package

我在使用 Flask Session Captcha 时遇到问题,因为模块 flask_session_captcha 似乎以错误的方式调用 captchaCatpcha python package 表示只要安装了模块 captcha 但它不工作,它就会提供 captcha.image

当我在 flask_session_captcha 尝试加载 captcha.image 模块时尝试启动我的 Flask 应用程序时出现以下错误:

Error: While importing "captcha", an ImportError was raised:

Traceback (most recent call last):
  File "/home/john/devel/Flask/authcaptcha/venv/lib64/python3.9/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/home/john/devel/Flask/authcaptcha/captcha.py", line 5, in <module>
    from flask_session_captcha import FlaskSessionCaptcha
  File "/home/john/devel/Flask/authcaptcha/venv/lib64/python3.9/site-packages/flask_session_captcha/__init__.py", line 5, in <module>
    from captcha.image import ImageCaptcha
ModuleNotFoundError: No module named 'captcha.image'; 'captcha' is not a package

我有 运行 pip install captcha 并且安装了版本 0.3-py3-none-any

不要将你的模块命名为capture.py,它与包名(capture)相同,这会导致导入冲突。