I am not an expert in python. I am trying to create a sample web application and I could run it with flask. However, after packaging it and trying to install it using waitress I am getting the error -
No module named helloweb.py (that is my web application). I am not sure how to troubleshoot this issue. Any pointers would be great. All the other answers on stack overflow did not help me much.
Here is my web application -
helloweb.py -
import datetime
from flask import Flask
from flask_api import status
import json
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello!'
@app.route('/xyz')
def display_status():
healthstatus=json.dumps({'status': status.HTTP_200_OK})
return healthstatus
I tried the following and it worked -
FLASK_APP=helloweb.py
FLASK_RUN_PORT=8080
flask run
But trying to port it on the WSGI production server waitress is not working for me. I did the following, created a setup.py file -
import setuptools
from setuptools import setup
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="mydomain-webapp-myusername", # Replace with your own username
version="0.0.1",
author="first.last",
author_email="someone@gmail.com",
description="A small flask package",
long_description="This is a web app",
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
and I created a LICENSE, README.md file, init.py file,waitress_server.py file in the same folder as the source file (helloweb.py). I am not sure why I am seeing the following error when I run -
$ waitress-serve --call 'helloweb:app'
Error: Bad module 'helloweb'
Usage:
waitress-serve [OPTS] MODULE:OBJECT
.........
........
..........
There was an exception (ImportError) importing your module.
It had these arguments:
1. No module named flask_api
I am able to import flask_api in the python shell and also helloweb.py, so I am not sure how to fix this. How do I troubleshoot this error?