ImportError: No module named flask_restful
Asked Answered
G

4

17

I am trying to deploy appengine flex python app but getting the following in Stackdriver log stderr after deployment

  File "/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/local/lib/python2.7/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/home/vmagent/app/my_service/entry_point.py", line 5, in <module>
    import flask_restful as restful
ImportError: No module named flask_restful

entry_point.py in line 5 has

import flask_restful as restful

And my requirement.txt has

Flask-RESTful==0.3.6
gunicorn==19.7.1

Not sure why its still complaining about Flask-Restful

Groningen answered 6/7, 2018 at 15:45 Comment(3)
Apparently imports can be case sensitive, maybe check that out? Flask-RESTful in your requirements isn't all lowercase like most packages I've seen...Heath
that was the problem. Not sure why it works when we use pip from command line.Groningen
Since that was the solution to the problem, may, @Sagasaki, post the good answer not as a comment but as an answer in order SoulMan be able to accept it and thus so help other SO users?Mcgowen
H
10

Imports are case sensitive on certain platforms, namely Linux (Windows and Mac may or may not care about case). The package Flask-RESTful isn't all lowercase like most packages (as per PEP 8 recommendation), so import flask_restful as restful will yield an import error unless the proper case is used.

Heath answered 9/7, 2018 at 14:33 Comment(0)
M
23

ImportError: No module named flask_restful

Seems that you don't have flask_restful installed, to install run:

pip install flask-restful

in your Terminal and then run your app.

Documentation: https://flask-restful.readthedocs.io/en/latest/installation.html

Maurilla answered 9/10, 2018 at 1:16 Comment(1)
Might also be pip3 install flask-restfulCandiot
H
10

Imports are case sensitive on certain platforms, namely Linux (Windows and Mac may or may not care about case). The package Flask-RESTful isn't all lowercase like most packages (as per PEP 8 recommendation), so import flask_restful as restful will yield an import error unless the proper case is used.

Heath answered 9/7, 2018 at 14:33 Comment(0)
S
1

I had the same problem... I was running my app using the "Play" button of Visual Studio Code and was stuck. Everything was already installed... After a while I realized that I had to use the console of the IDE and start the program from there:

python App.py

I was running it under a Virtual Environment

Seismograph answered 27/3, 2020 at 18:0 Comment(0)
O
1
  1. basically your project root directory is not matching with your python root directory for this specific (flask_restful) package,,

  2. uninstall python application and reinstall it on window programs files, you should install python in your window programs not separately

    i resolved it by this procedure (happy coding)

Outlast answered 19/10, 2020 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.