0

I'm trying to use flask-uploads for image upload feature in my flask app.

I used pip install Flask-Uploads to install and pip install Flask-Uploads --upgrade to upgrade the flask-uploads module. But when I import it, it gives me an error, here's my import code:

from flaskext.uploads import UploadSet, configure_uploads, IMAGES

Error:

File "project.py", line 3, in <module>
from flaskext.uploads import UploadSet, configure_uploads, IMAGES
ImportError: No module named flaskext.uploads

I tried using an older version by doing pip install Flask-Uploads==0.1.3 even that doesn't work.

I'm using Windows 10.

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37

2 Answers2

1

Update: Suggested is the OP further drills down in changes of flask vs. flask-upload that introduced the incompatibility noted at the end of this troubleshooting aid / documentation. Maybe the maintainers of the packages even can provide answers, if the OP kindly asks them? When futher details are provided I offer to update this to a solution, but for now they seem to miss ...

**Answer [on hold] **

I think you missed a dot. Try:

from flask.ext.uploads import UploadSet, configure_uploads, IMAGES

instead of:

from flaskext.uploads import UploadSet, configure_uploads, IMAGES

If the module is still not found, than check sys.path and check, if the installed module is in one of the visited places. Like so:

>> import sys
>>> sys.path
['', '/usr/local/some/python', '/usr/local/lib/python2.7/site-packages']

Empty is current working directory, rest are folder paths and if you know where the install stored the module /usr/local/lib/python2.7/site-packages/flask_uploads.pywe know it finds it.

Then if you encounter:

>>> import flask_uploads
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/flask_uploads.py", line 24, in <module>
    from flask import current_app, Module, send_from_directory, abort, url_for
ImportError: cannot import name Module

it tells you, that in flask_uploads.pyof the install package, you cannot import Modulefrom flask.

So:

>>> import flask
>>> dir(flask)
['Blueprint', 'Config', 'Flask', 'Markup', 'Request', 'Response', 'Session', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_app_ctx_stack', '_compat', '_request_ctx_stack', 'abort', 'after_this_request', 'app', 'appcontext_popped', 'appcontext_pushed', 'appcontext_tearing_down', 'before_render_template', 'blueprints', 'cli', 'config', 'copy_current_request_context', 'ctx', 'current_app', 'escape', 'flash', 'g', 'get_flashed_messages', 'get_template_attribute', 'globals', 'got_request_exception', 'has_app_context', 'has_request_context', 'helpers', 'json', 'json_available', 'jsonify', 'make_response', 'message_flashed', 'redirect', 'render_template', 'render_template_string', 'request', 'request_finished', 'request_started', 'request_tearing_down', 'safe_join', 'send_file', 'send_from_directory', 'session', 'sessions', 'signals', 'signals_available', 'stream_with_context', 'template_rendered', 'templating', 'url_for', 'wrappers']

Hm ... looks not so promising but someone or some place of changes documentation shoud show, when this import broke in flask-uploads.

Dilettant
  • 3,267
  • 3
  • 29
  • 29
0

Update 2020:

You should import from flask_uploads import Uploadset.

The PyPi package of Flask-Uploads is broken since February 2020.

You can use the drop-in replacement Flask-Reuploaded.

https://pypi.org/project/Flask-Reuploaded/

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37