flask: 报错:ImportError: cannot import name 'secure_filename' from 'werkzeug'

一,报错信息:

$ flask db init
/data/python/flask/panda-sys/venv/lib/python3.10/site-packages/pymilvus/client/__init__.py:6: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import DistributionNotFound, get_distribution
Error: While importing 'main', an ImportError was raised:

Traceback (most recent call last):
  File "/data/python/flask/panda-sys/venv/lib/python3.10/site-packages/flask/cli.py", line 245, in locate_app
    __import__(module_name)
  File "/data/python/flask/panda-sys/main.py", line 11, in <module>
    from app import create_app, db
  File "/data/python/flask/panda-sys/app/__init__.py", line 28, in <module>
    from flask_uploads import UploadSet, configure_uploads, patch_request_class
  File "/data/python/flask/panda-sys/venv/lib/python3.10/site-packages/flask_uploads.py", line 26, in <module>
    from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug' (/data/python/flask/panda-sys/venv/lib/python3.10/site-packages/werkzeug/__init__.py)


Usage: flask [OPTIONS] COMMAND [ARGS]...
Try 'flask --help' for help.

Error: No such command 'db'.

二,解决 :

编辑:

/data/python/flask/panda-sys/venv/lib/python3.10/site-packages/flask_uploads.py

注释掉:

# from werkzeug import secure_filename, FileStorage

增加:

from werkzeug.utils import secure_filename
from werkzeug.datastructures import  FileStorage

如下:

# from werkzeug import secure_filename, FileStorage
from werkzeug.utils import secure_filename
from werkzeug.datastructures import  FileStorage

 

posted @ 2025-11-10 13:54  刘宏缔的架构森林  阅读(33)  评论(0)    收藏  举报