ImportError: Nenhum módulo chamado os [Python + Flask + uwsgi + Ngnix + Ubuntu16.04]

1

Eu tento hospedar minha página em um servidor com o sistema operacional Ubuntu 16.04 e Python2 / Flask / uwsgi (emperor) .

A configuração do emperor em /etc/uwsgi/emperor.ini é a seguinte:

[uwsgi]

emperor = /etc/uwsgi/vassals

uid = www-data

gid = www-data

e o serviço emperor pode ser iniciado normalmente, pois os resultados de sudo systemctl status emperor.uwsgi mostram que o arquivo uwsgi ini está carregado normalmente:

?.emperor.uwsgi.service - uWSGI Emperor
  Loaded: loaded (/etc/systemd/system/emperor.uwsgi.service; enabled; vendor preset: enable
  Active: active (running) since Sun 2017-01-08 00:18:03 EST; 43min ago
 Main PID: 150 (uwsgi)
  Status: "The Emperor is governing 1 vassals"
  CGroup: /system.slice/emperor.uwsgi.service
          ?..150 /usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
          ?..160 /usr/local/bin/uwsgi --ini proxy.ini
          ?..172 /usr/local/bin/uwsgi --ini proxy.ini
Jan 08 00:18:03 localhost uwsgi[150]: *** WARNING: you are running uWSGI without its master 
Jan 08 00:18:03 localhost uwsgi[150]: your processes number limit is 579533
Jan 08 00:18:03 localhost uwsgi[150]: your memory page size is 4096 bytes
Jan 08 00:18:03 localhost uwsgi[150]: detected max file descriptor number: 1024
Jan 08 00:18:03 localhost uwsgi[150]: * ** starting uWSGI Emperor ***
Jan 08 00:18:03 localhost systemd[1]: Started uWSGI Emperor.
Jan 08 00:18:03 localhost uwsgi[150]: * ** has_emperor mode detected (fd: 7) ***
Jan 08 00:18:03 localhost uwsgi[150]: [uWSGI] getting INI configuration from proxy.ini
Jan 08 00:18:03 localhost uwsgi[150]: Sun Jan  8 00:18:03 2017 - [emperor] vassal proxy.ini 
Jan 08 00:18:03 localhost uwsgi[150]: Sun Jan  8 00:18:03 2017 - [emperor] vassal proxy.ini 

O diretório da página da Web é /var/www/proxy e o arquivo uwsgi ini é /var/www/proxy/proxy.ini da seguinte forma:

[uwsgi]
base = /var/www/proxy
app = index
module = %(app)
home = %(base)
pythonpath = %(base)
socket = /var/www/proxy/%n.sock
chmod-socket  = 666 
callable = app 
logto = /var/log/uwsgi/%n.log
no-site=true

O arquivo de configuração do nginx /etc/nginx/sites-enabled/proxy :

upstream flask {
    server unix:///var/www/proxy/proxy.sock;
}

# Default server configuration
server {
    listen 80;
    server_name proxy.foool.net;
    charset utf-8;

    location / {
        uwsgi_pass flask;
        include uwsgi_params;
    }
}

No entanto, ele retorna um Internal Server Error ao abrir a página da Web, e o arquivo de log /var/log/uwsgi/proxy.log mostra um erro ImportError: No module named os . veja mais detalhes:

machine: x86_64
compiled with version: 5.4.0 20160609 on 07 January 2017 23:28:17
os: Linux-2.6.32-042stab113.21 #1 SMP Wed Mar 23 11:05:25 MSK 2016
nodename: localhost
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 579533
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/proxy/proxy.sock fd 3
Python version: 2.7.12 (default, Nov 19 2016, 06:48:10)  [GCC 5.4.0 20160609]
Set PythonHome to /var/www/proxy
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1fb4bf0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/proxy/ to pythonpath.
Traceback (most recent call last):
  File "/var/www/proxy/index.py", line 2, in <module>
    import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 160)
spawned uWSGI worker 1 (pid: 172, cores: 1)

Então, como posso resolver este problema ImportError ? Meu python padrão é python2.7.12 e o pip3 não está instalado.

Atualização:

Ignore o systemctl e emperor , meu projeto está rodando com o comando uwsgi --socket 0.0.0.0:5000 --protocol=http -w index:application , então acho que o uwsgi está bem.

    
por foool 08.01.2017 / 07:38

0 respostas