uWSGI使用插件Python36运行Python 2->在Venv中找不到Django

时间:2019-08-14 13:31:42

标签: django linux nginx deployment uwsgi

我正在通过此教程在Centos7服务器上使用Nginx,uWSGI和Nginx设置一个简单的Django项目:

How to Serve Django Applications with uWSGI and Nginx on CentOS 7

但是我尝试将这个项目更改为使用Python 3.6

运行Django 2

一切正常,直到创建 firstsite.ini 文件。

  1 [uwsgi]
  2 project = firstsite
  3 username = user
  4 base = /home/%(username)
  5 plugins-dir = /usr/lib64/uwsgi/
  6 plugin = python36
  7 virtualenv = %(base)/Env/%(project)
  8 chdir = %(base)/%(project)
  9 home = %(base)/Env/%(project)
 10 module = %(project).wsgi:application
 11 
 12 master = true
 13 processes = 5
 14 
 15 uid = %(username)
 16 socket = /run/uwsgi/%(project).sock
 17 chown-socket = %(username):nginx
 18 chmod-socket = 660
 19 vacuum = true

我陷入了困境。设置并尝试访问Django站点时,出现内部服务器错误。检查错误日志文件和消息后,我在我的.ini文件中实现了 logto

   21 #Error Logs
   22 logto = %(base)/%(project)/error.log

检查此文件后,它告诉我此错误消息::

*** Starting uWSGI 2.0.18 (64bit) on [Wed Aug 14 13:27:24 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-36) on 23 July 2019 10:27:56
os: Linux-3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019
nodename: ip-172-31-34-37.eu-central-1.compute.internal
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/sites
detected binary path: /usr/bin/uwsgi
chdir() to /home/user/firstsite
your processes number limit is 3775
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 /run/uwsgi/firstsite.sock fd 3
setuid() to 1001
Python version: 2.7.5 (default, Jun 20 2019, 20:27:34)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Set PythonHome to /home/user/Env/firstsite
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x234f0e0
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 ***
Traceback (most recent call last):
  File "./firstsite/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
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: 21976)
spawned uWSGI worker 1 (pid: 21978, cores: 1)
spawned uWSGI worker 2 (pid: 21979, cores: 1)
spawned uWSGI worker 3 (pid: 21980, cores: 1)
spawned uWSGI worker 4 (pid: 21981, cores: 1)
spawned uWSGI worker 5 (pid: 21982, cores: 1)

如果我手动尝试使用相同的Env运行此django项目,则没有问题。所以我认为可能是因为uwsgi正在运行Python 2.7.5而不是Python 3.6。

我还使用 uwsgi --plugin python36 -s:0

检查了插件python
*** Starting uWSGI 2.0.18 (64bit) on [Thu Aug 15 04:16:19 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-36) on 14 August 2019 14:16:35
os: Linux-3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019
nodename: ip-172-31-34-37.eu-central-1.compute.internal
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /usr/lib64/uwsgi
detected binary path: /usr/local/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3775
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 TCP address :37796 (port auto-assigned) fd 3
Python version: 3.6.8 (default, Apr 25 2019, 21:02:35)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x17756c0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 6476, cores: 1)

在我看来,我已经以正确的方式创建了我的36插件。 如果有人可以帮助我,我将非常感激。

1 个答案:

答案 0 :(得分:0)

这是真正的问题所在,找不到Django 您确定在您提到的那个环境中安装了django吗? 我的意思是“ Env”

Traceback (most recent call last):
  File "./firstsite/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi

在您提到的那个链接中我找不到

virtualenv = %(base)/Env/%(project)

尝试将其更改为

virtualenv = %(base)/Env

如果这不能解决您的问题,请指定Django,您正在使用的python版本以及您的项目结构