[通过uwsgi启动Flask时未加载任何应用程序

问题描述 投票:0回答:1

我知道这是一个普遍的问题,但是由于我已经搜索了3个小时,并且考虑到必须涉及量子奇点,因此我不得不发布此信息。

我一直收到这个熟悉的错误:

[uWSGI] getting INI configuration from uwsgi.ini,
*** Starting uWSGI 2.0.18-debian (64bit) on [Mon May 25 15:56:04 2020] ***,
compiled with version: 8.2.0 on 10 February 2019 02:42:46,
os: Linux-5.6.12-1-MANJARO #1 SMP PREEMPT Sun May 10 14:36:43 UTC 2020,
nodename: a43c6a7bbb2c,
machine: x86_64,
clock source: unix,
pcre jit disabled,
detected number of CPU cores: 8,
current working directory: /srv/myapp,
detected binary path: /usr/bin/uwsgi-core,
setgid() to 33,
setuid() to 33,
your memory page size is 4096 bytes,
detected max file descriptor number: 1048576,
lock engine: pthread robust mutexes,
thunder lock: disabled (you can enable it with --thunder-lock),
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.socket fd 3,
your server socket listen backlog is limited to 100 connections,
your mercy for graceful operations on workers is 60 seconds,
mapped 437520 bytes (427 KB) for 5 cores,
*** Operational MODE: preforking ***,
*** no app loaded. going in full dynamic mode ***,
*** uWSGI is running in multiple interpreter mode ***,
!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!,
no request plugin is loaded, you will not be able to manage requests.,
you may need to install the package for your language of choice, or simply load it with --plugin.,
!!!!!!!!!!! END OF WARNING !!!!!!!!!!,
spawned uWSGI master process (pid: 25),
spawned uWSGI worker 1 (pid: 28, cores: 1),
spawned uWSGI worker 2 (pid: 29, cores: 1),
spawned uWSGI worker 3 (pid: 30, cores: 1),
spawned uWSGI worker 4 (pid: 31, cores: 1),
spawned uWSGI worker 5 (pid: 32, cores: 1),

但是,通过这种非常简单的设置,我没有发现任何问题。我的设置:

core / __ init __。py

from flask import Flask

def create_app():

    app = Flask(__name__)

    @app.route('/')
    def hello_world():
        return 'Hello, World!'

    return app

app.py

from core import create_app

app = create_app()

if __name__ == '__main__':
    app.run()

Dockerfile

FROM python:3.6-slim

RUN apt-get clean \
    && apt-get -y update
RUN apt-get -y install uwsgi nginx

COPY . /srv/myapp
COPY nginx.conf /etc/nginx
WORKDIR /srv/myapp

RUN pip install -r requirements.txt

RUN chmod +r uwsgi.ini
RUN chmod +x ./start.sh
CMD ["./start.sh"]

start.sh

#!/usr/bin/env bash
service nginx start
uwsgi --ini uwsgi.ini

uwsgi.ini

[uwsgi]
module = app:app
uid = www-data
gid = www-data
master = true
processes = 5
socket = /tmp/uwsgi.socket
chmod-sock = 664
vacuum = true
die-on-term = true

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;events 
{
    worker_connections 1024;
    use epoll;
    multi_accept on;
}
http {
    access_log /dev/stdout;
    error_log /dev/stdout;    
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;    
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;    
    index   index.html index.htm;    
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /var/www/html;        
        location / 
        {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/uwsgi.socket;
        }
    }
}

如果我在DOCKERFILE中添加python3插件RUN apt-get -y install uwsgi nginx uwsgi-plugin-python3并通过uwsgi --ini uwsgi.ini --plugin python3运行uwsgi,则会得到:

Traceback (most recent call last):
  File "./app.py", line 1, in <module>
    from core import create_app
  File "./core/__init__.py", line 1, in <module>
    from flask import Flask
ModuleNotFoundError: No module named 'flask'

我不知道这是否是一个提示。任何帮助表示赞赏!谢谢!

python python-3.x flask dockerfile uwsgi
1个回答
0
投票

经过八小时的睡眠,我发现了我的错误:

通过apt-get安装uwsgi将不起作用。需要通过pip install安装uwsgi。 (我的猜测是,这是两个不同的uwsgi实例/服务)

© www.soinside.com 2019 - 2024. All rights reserved.