ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

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

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, dbFile "/data/python/flask/panda-sys/app/__init__.py", line 28, in <module>from flask_uploads import UploadSet, configure_uploads, patch_request_classFile "/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

 

返回列表