0
votes

I installed flask-upload module in windows 10:

pip install flask flask-wtf flask-uploads

The results were:

Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 WTForms-2.3.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 flask-uploads-0.2.1 flask-wtf-0.14.3 itsdangerous-1.1.0

Then in the text editor there is an error when I import the module as shown in the screenshot. unable to import flask-uploads

After running the app.py the following are the errors in cmd:

Error: While importing "app", an ImportError was raised:
Traceback (most recent call last):
  File "c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\flask\cli.py", line 240, in locate_app
    __import__(module_name)
  File "C:\Users\seanv\OneDrive\Documents\web dev\##pprojects\flask\flask_uploads\app.py", line 4, in <module>
    from flask_uploads import configure_uploads, IMAGES, UploadSet
  File "c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\flask_uploads.py", line 26, in <module>
    from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug' (c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\werkzeug\__init__.py)

May someone who understands the problem help me with possible solutions or suggestions. Thank you in advance.

1
pip is installing packages for python2 by default (not sure for windows). I guess you want to use python3, use pip3 instead pip.Buğra İşgüzar
It's werkzeug.utils.secure_filename, not werkzeug.secure_filenameKen Kinder
Thanks @KenKinder your suggestion was successful. But why that error since it was in a file installed with the module?Valentine Sean
I couldn't say. Perhaps the file upload library you're using is out of date or unmaintained??Ken Kinder

1 Answers

0
votes

Your app is using Flask-Uploads.

Back in February 2020, there was an update for Werkzeug, a library which Flask and many libraries, including Flask-Uploads, is based on.

This update introduced a breaking change, as Werkzeug changed its API, ie. the import of secure_filename.

I provided a pull request to Flask-Uploads, which the maintainer accepted. But very sadly and unfortunately the maintainer did not want to provide a new package for PyPi.

So, while you could install the updated Flask-Uploads via a commit id from its GitHub repository, you cannot any longer install it from PyPi.

I asked the maintainer for a new release, I also offered my help, but no chance.

So, finally, I decided to fork the library.

Here is the new package on PyPi https://pypi.org/project/Flask-Reuploaded/

Here is the repository https://github.com/jugmac00/flask-reuploaded

It is a drop-in replacement. So you just have to install the new package and it just works. No need to change any imports or code in your application.