我花了一天时间试图解决这个问题。
我正在Digital Ocean
上运行Django
、Python3.6
、Nginx
、Ubuntu 16.04
和uWSGI
。
不得不通过deadsnakesppa
安装Python3.6
并有一个我创建的virtualenv
mkvirtualenv --python=python3.6 myproject
我正在遵循我之前遵循的本教程,但是当我尝试运行以下代码来测试应用程序服务器(不在 virtualenv 中)时
uwsgi --http :8080 --home /home/user/Env/myproject --chdir /home/user/myproject/src/myproject -w myproject.wsgi
我得到这个回溯
*** Starting uWSGI 2.0.18 (64bit) on [Mon Aug 5 12:23:53 2019] ***
compiled with version: 5.4.0 20160609 on 05 August 2019 11:53:48
os: Linux-4.4.0-157-generic #185-Ubuntu SMP Tue Jul 23 09:17:01 UTC 2019
nodename: myproject
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/user/myproject/src/myproject
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3898
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 http bound on :8080 fd 4
spawned uWSGI http 1 (pid: 17338)
uwsgi socket 0 bound to TCP address 127.0.0.1:34660 (port auto-assigned) fd 3
Python version: 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x21aaf90
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./myproject/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
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 worker 1 (and the only) (pid: 17337, cores: 1)
当我激活虚拟环境时,我得到相同的结果。
其他错误日志是
Aug 05 12:18:20 myproject uwsgi[16998]: --- no python application found, check your system...
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Main process exited, code=exited, status=203/EXEC
Aug 05 11:39:47 myproject systemd[1]: Failed to start uWSGI Emperor service.
Aug 05 11:39:47 wmyproject systemd[1]: uwsgi.service: Unit entered failed state.
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Failed with result 'exit-code'.
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart.
Aug 05 11:39:47 myproject systemd[1]: Stopped uWSGI Emperor service.
Aug 05 11:39:47 myproject systemd[1]: Starting uWSGI Emperor service...
Aug 05 11:39:47 myproject systemd[14970]: uwsgi.service: Failed at step EXEC spawning /usr/local/bin/uwsgi: No such file or directory
如果我运行以下内容(不在虚拟环境中)
python3 -c 'import django.core.wsgi'
我得到
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'django'
但是如果我在虚拟环境中运行它,则不会出错,这意味着该错误与uWSGI
有关。
从我的manage.py
级别运行python manage.py runserver
工作正常。
pip3 -V
给pip 19.2.1 from /home/user/.local/lib/python3.6/site-packages/pip (python 3.6)
python3.6 -V
给Python 3.6.9
我尝试使用sudo -H pip3 install uwsgi
重新安装uWSGI,它似乎总是安装到python 3.5 site-packages
。
如果我在虚拟环境中运行pip3 install uwsgi
它会安装到
Uninstalling uWSGI-2.0.18:
Would remove:
/home/user/Env/myproject/bin/uwsgi
/home/user/Env/myproject/lib/python3.6/site-packages/uWSGI-2.0.18.dist-info/*
/home/user/Env/myproject/l
ib/python3.6/site-packages/uwsgidecorators.py
我的.ini文件
[uwsgi]
project = myproject
uid = user
base = /home/%(uid)
chdir = %(base)/%(project)/src/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
我的File: /etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown user:www-data /run/uwsgi'
ExecStart=/home/user/Env/myproject/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
我的项目显然需要python3.6才能运行,而且我没有解决方案,任何人都可以提供任何建议吗?
如果你在系统上使用两个不同版本的python(你的系统范围的python似乎是3.5.2),那么你应该pip install uwsgi
包含你将要使用的python版本的virtualenv。
然后你应该直接使用它的路径来启动那个特定的uwsgi,在你的例子中是/home/user/Env/myproject/bin/uwsgi:
> /home/user/Env/myproject/bin/uwsgi --ini /path/to/file/uwsgi.ini
或
> /home/user/Env/myproject/bin/uwsgi --http :8080 --home /home/user/Env/myproject --chdir /home/user/myproject/src/myproject -w myproject.wsgi