I am new to python and flask. I want to use flask-restplus. On using flask restplus, I am unable to start my app with "flask run" command. However, it does start when I run it as module "python3 -m flask run". My first question is there any difference starting it as a module vs the normal way? Secondly, what's the reason it doesn't start with "flask run" in this case. Am I missing something here?
Here is a simple sample app with flask restplus:
from flask import Flask
from flask_restplus import Resource, Api
app = Flask(__name__) # Create a Flask WSGI application
api = Api(app) # Create a Flask-RESTPlus API
@api.route('/hello') # Create a URL route to this resource
class HelloWorld(Resource): # Create a RESTful resource
def get(self): # Create GET endpoint
return {'hello': 'world'}
if __name__ == '__main__':
app.run()
Here is the output of "flask run" command:
(venv) ~/C/e/s/testpython ❯❯❯ flask run
* Serving Flask app "app.py"
* Environment: local
* Debug mode: off
Usage: flask run [OPTIONS]
Error: While importing "app", an ImportError was raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/cli.py", line 235, in locate_app
__import__(module_name)
File "/Users/rajatarora/Code/eon/sales-plus/testpython/app.py", line 2, in <module>
from flask_restplus import Resource, Api
ModuleNotFoundError: No module named 'flask_restplus'
and the output using "python3 -m flask run" command:
(venv) ~/C/e/s/testpython ❯❯❯ python3 -m flask run ✘ 2
* Serving Flask app "app.py"
* Environment: local
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
flask resplus is ofcourse installed. Here is output of pip freeze
(venv) ~/C/e/s/testpython ❯❯❯ pip freeze
aniso8601==8.0.0
attrs==19.3.0
Click==7.0
Flask==1.1.1
flask-restplus==0.13.0
importlib-metadata==0.23
itsdangerous==1.1.0
Jinja2==2.10.3
jsonschema==3.2.0
MarkupSafe==1.1.1
more-itertools==7.2.0
pyrsistent==0.15.5
pytz==2019.3
six==1.13.0
Werkzeug==0.16.0
zipp==0.6.0