I'm trying to import secure_filename from werkzeug.utils and it shoot an error. It works fine under my base virtual env.
code:
# Flask packages
from flask import Flask, render_template, request, session, redirect, flash, send_file
from flask_bootstrap import Bootstrap
from flask_uploads import UploadSet,configure_uploads,IMAGES,DATA,ALL
# Systems
import os
import sys
import json
from werkzeug.utils import secure_filename
Error:
(absa_annotation) C02QM3FSFVH3:ABSA-annotation-tool kwunkeilau$ python3 app.py
Traceback (most recent call last):
File "app.py", line 4, in <module>
from flask_uploads import UploadSet,configure_uploads,IMAGES,DATA,ALL
File "/Users/kwunkeilau/anaconda3/envs/absa_annotation/lib/python3.7/site-packages/flask_uploads.py", line 26, in <module>
from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug' (/Users/kwunkeilau/anaconda3/envs/absa_annotation/lib/python3.7/site-packages/werkzeug/__init__.py)
That exception looks like
Flask-Uploadsis trying tofrom werkzeug import secure_filenamewhich should befrom werkzeug.utils import secure_filename, as per your own code.Going by the
Flask-Uploadsgithub repo this appears to have been fixed 12 months ago.I'd try
pip install -U flask-uploadsin 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):
Or in a
requirements.txt:Then
pip install -r requirements.txt.Which works wonders: