首页 > 解决方案 > waitress-serve --call 'helloweb:app' 给出模块异常

问题描述

我不是python专家。我正在尝试创建一个示例 Web 应用程序,我可以使用烧瓶运行它。但是,在打包并尝试使用女服务员安装它之后,我收到了错误 -

没有名为 helloweb.py 的模块(这是我的 Web 应用程序)。我不确定如何解决此问题。任何指针都会很棒。关于堆栈溢出的所有其他答案对我没有多大帮助。

这是我的网络应用程序 -

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

我尝试了以下方法,它奏效了-

FLASK_APP=helloweb.py
FLASK_RUN_PORT=8080

flask run

但是尝试将它移植到 WSGI 生产服务器服务员上对我不起作用。我做了以下,创建了一个 setup.py 文件 -

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',
)

我在与源文件 (helloweb.py) 相同的文件夹中创建了一个 LICENSE、README.md 文件、init .py 文件、waitress_server.py 文件。我不确定为什么我在运行时看到以下错误 -

$ 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

我可以在 python shell 和 helloweb.py 中导入 flask_api,所以我不知道如何解决这个问题。如何解决此错误?

标签: pythonflaskwaitress

解决方案


推荐阅读