That exception looks like Flask-Uploads is trying to from werkzeug import secure_filename which should be from werkzeug.utils import secure_filename, as per your own code.
Going by the Flask-Uploads github repo this appears to have been fixed 12 months ago.
I'd try pip install -U flask-uploads in your virtual environment, to ensure the latest version.
EDIT:
As @mattficke points out, the PyPi version is dated, and there's not a more recent release on the repo. Turns out you can install directly based on a commit hash, so for the latest (at the time of writing this):
pip install git+https://github.com/maxcountryman/flask-uploads.git@f66d7dc
Or in a requirements.txt:
git+https://github.com/maxcountryman/flask-uploads.git@f66d7dc
Then pip install -r requirements.txt.
Which works wonders:
>>> from flask_uploads import UploadSet,configure_uploads,IMAGES,DATA,ALL
>>> # No Exception
Answer from v25 on Stack OverflowThat exception looks like Flask-Uploads is trying to from werkzeug import secure_filename which should be from werkzeug.utils import secure_filename, as per your own code.
Going by the Flask-Uploads github repo this appears to have been fixed 12 months ago.
I'd try pip install -U flask-uploads in your virtual environment, to ensure the latest version.
EDIT:
As @mattficke points out, the PyPi version is dated, and there's not a more recent release on the repo. Turns out you can install directly based on a commit hash, so for the latest (at the time of writing this):
pip install git+https://github.com/maxcountryman/flask-uploads.git@f66d7dc
Or in a requirements.txt:
git+https://github.com/maxcountryman/flask-uploads.git@f66d7dc
Then pip install -r requirements.txt.
Which works wonders:
>>> from flask_uploads import UploadSet,configure_uploads,IMAGES,DATA,ALL
>>> # No Exception
Alternatively to above suggested solution, you can use the well maintained fork called Flask-Reuploaded.
You do not even have to change import statements, as it tries to stay compatible with the no longer well maintained Flask-Uploads.
See https://github.com/jugmac00/flask-reuploaded
Also, Flask-Reuploaded certainly provides uptodate packages on PyPI:
https://pypi.org/project/Flask-Reuploaded/
bookshelf error on App Engine: "ImportError: cannot import name 'secure_filename' from 'werkzeug'"
Cannot import `secure_filename`
Import Error when importing secure_filename from Werkzeug.utils : Forums : PythonAnywhere
werkzeug fails to import secure_filename within Docker
In flask_uploads.py
Change
from werkzeug import secure_filename,FileStorage
to
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
According to this issue, it is a bug related to the current version 1.0.0 of workzeug. It's merged but not yet published in pypi.
The workaround know until now is to downgrade from werkzeug=1.0.0 to werkzeug==0.16.0
So for do that you just need run the command:
pip install -U Werkzeug==0.16.0
Looking in the release notes from werkzeug there is a version 0.16.1, but in bug report there is no evidence that using that version could be of any help.
Hi, I'm trying to deploy my flask app to heroku and it uses the package Flask-Uploads. Though it keeps saying "ImportError: cannot import name 'secure_filename' from 'werkzeug' ". I've tried to change the import but I guess heroku just gets the lastest update to the package.