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

标签 django linux nginx deployment uwsgi

我正在尝试使用本教程在我的 Centos7-Server 上使用 Nginx、uWSGI 设置一个简单的 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)

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

我还检查了插件 python uwsgi --plugin python36 -s:0

*** 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 插件。 如果有人能帮助我,我将不胜感激。

最佳答案

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

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 版本以及您的项目结构

关于django - uWSGI 使用插件 Python36 运行 Python 2 -> 在 Venv 中找不到 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57495794/

相关文章:

linux - bash 4.4 不将变量传递给子 shell

Linux 庆典 : Combine two csv files with different headers

docker - Nginx 速率限制问题 : Invalid number of arguments

linux - Apache DirectoryRoot 配置?

django - 当通过管理站点修改 Django CharField 时发送电子邮件通知

python - Django - OneToOneField 未在管理中填充

python - Django 将错误列表输出为字符串而不是 html

ruby-on-rails - 将自定义HTTP header 添加到Nginx X-Accel-Redirect

ubuntu - 删除 Nginx 并使用 Pagespeed 模块安装 Nginx

python - django 中的 PyCallGraph 中间件