ImportError:无法导入名称“ UserAgentMixin”

时间:2019-10-25 08:02:39

标签: python flask importerror werkzeug

我想初始化Flask DB时遇到问题,这是终端结果:

user@Pc:~/Documents/test$ flask db init
Traceback (most recent call last):
  File "/home/user/.local/bin/flask", line 7, in <module>
    from flask.cli import main
  File "/home/user/.local/lib/python3.6/site-packages/flask/__init__.py", line 17, in <module>
    from werkzeug.exceptions import abort
  File "/home/user/.local/lib/python3.6/site-packages/werkzeug/__init__.py", line 151, in <module>
    __import__('werkzeug.exceptions')
  File "/home/user/.local/lib/python3.6/site-packages/werkzeug/exceptions.py", line 71, in <module>
    from werkzeug.wrappers import Response
  File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/__init__.py", line 30, in <module>
    from .request import PlainRequest
  File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/request.py", line 6, in <module>
    from .user_agent import UserAgentMixin
  File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/user_agent.py", line 1, in <module>
    from ..useragents import UserAgent
  File "/home/user/.local/lib/python3.6/site-packages/werkzeug/useragents.py", line 212, in <module>
    from werkzeug.wrappers import UserAgentMixin  # noqa
ImportError: cannot import name 'UserAgentMixin'

我正在使用FlaskSQLAlchemyPythonPostgreSQL开发Ubuntu 18.04 LTS。从哪里发生此错误,我该如何解决?

P.S:我关注Flask的{​​{3}}

编辑1:Werkzeug已安装

(venv) user@Pc:~/Documents/test$ pip install Werkzeug
Requirement already satisfied: Werkzeug in ./venv/lib/python3.6/site-packages

编辑2:我不知道为什么会遇到这个问题,但是删除空格缩进后该错误消失了

1 个答案:

答案 0 :(得分:1)

尝试pip install Werkzeug

UserAgentMixin来自werkzeug!

ref:https://tedboy.github.io/flask/generated/generated/werkzeug.UserAgentMixin.html