uWSGI - ImportError: No module named os

uWSGI - ImportError: No module named os

这很令人费解,因为 uWSGI 在 运行:

时工作
uwsgi --http :8003 --wsgi-file bigsky.wsgi

但不适用于:

uwsgi --ini uwsgi.ini --no-site

它returns这个错误:

Traceback (most recent call last):
  File "bigsky.wsgi", line 1, in <module>
    import os
ImportError: No module named os

正在部署:

代码如下:

uwsgi.ini:

[uwsgi]
# %d is the dir this configuration file is in

socket = 127.0.0.1:8003
chmod-socket = 666

uid = bsdev
gid = bsdev

master = true
enable-threads = true
processes = 4

# virtualenv
home = /home/bsdev/.virtualenvs/bs_py34

chdir = /www/django/releases/persistent/bsrs/python3/
wsgi-file = project.wsgi

env = DJANGO_SETTINGS_MODULE=project.settings.persistent

# create a pidfile
pidfile = /tmp/project-master.pid 
harakiri = 10 # respawn processes taking more than 20 seconds
max-requests = 5000 # respawn processes after serving 5000 requests

# will be run via `supervisord` so don't need to daemonize
# logto = /var/log/uwsgi/project.log
logdate = true
vacuum = true

project.wsgi:

import os
import sys


# python 3
sys.path.append('/usr/local/bin/python3.4')
sys.path.append('/usr/local/lib/python3.4/site-packages')

# project
sys.path.append('/www/django/releases/persistent/bsrs/python3')
sys.path.append('/www/django/releases/persistent/bsrs/bsrs-django')
sys.path.append('/www/django/releases/persistent/bsrs/bsrs-django/project')
sys.path.append('/www/django/releases/persistent/bsrs/bsrs-django/project/project')


# 1st instantiate wsgi
from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()

# Add the app directories to the PYTHONPATH
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings.persistent'


def application(environ, start_response):
    return _application(environ, start_response)

编辑:

我也收到此错误消息。它说 Python version: 2.7.5,但 Django App 应该是 运行 in python 3.4。这可能是个问题吗?

Tue Sep 22 13:25:12 2015 - thunder lock: disabled (you can enable it with --thunder-lock)
Tue Sep 22 13:25:12 2015 - uwsgi socket 0 bound to UNIX address /tmp/bigsky.sock fd 3
Tue Sep 22 13:25:12 2015 - Python version: 2.7.5 (default, Jun 24 2015, 00:41:19)  [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]
Tue Sep 22 13:25:12 2015 - Set PythonHome to /home/bsdev/.virtualenvs/bs_py34/
Tue Sep 22 13:25:12 2015 - Python main interpreter initialized at 0x25258f0
Tue Sep 22 13:25:12 2015 - python threads support enabled
Tue Sep 22 13:25:12 2015 - your server socket listen backlog is limited to 100 connections
Tue Sep 22 13:25:12 2015 - your mercy for graceful operations on workers is 60 seconds
Tue Sep 22 13:25:12 2015 - mapped 363840 bytes (355 KB) for 4 cores
Tue Sep 22 13:25:12 2015 - *** Operational MODE: preforking ***
Traceback (most recent call last):
  File "./bigsky/wsgi.py", line 1, in <module>
    import os
ImportError: No module named os

我遇到了这个问题,因为我没有在 Centos 7 上正确编译 uWSGI,然后需要用 Python 3.4 构建它。简而言之,这里是命令:

wget http://projects.unbit.it/downloads/uwsgi-2.0.3.tar.gz
tar -xvf uwsgi-2.0.3.tar.gz
cd uwsgi-2.0.3

source ~/path/to/virtualenv_python3.4/bin/activate

python uwsgiconfig.py --build

然后运行uWSGI:

sudo ~/misc/uwsgi-2.0.3/uwsgi --ini uwsgi.ini

您正在使用 python3,因此安装 uwsgipip3

pip3 install uwsgi