【问题标题】:uWSGI runs Python 2 with Plugin Python36 -> doesn't find Django in VenvuWSGI 使用插件 Python36 运行 Python 2 -> 在 Venv 中找不到 Django
【发布时间】:2019-12-21 01:49:17
【问题描述】:

我正在尝试使用本教程在我的 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 站点时,我遇到了内部服务器错误。检查错误日志文件和消息后,我已将 logto 实现到我的 .ini 文件中::

   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。

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

【问题讨论】:

    标签: django linux nginx deployment uwsgi


    【解决方案1】:

    这是真正的问题是它找不到 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 版本以及您的项目结构

    【讨论】:

    • 感谢您的回答!我需要 python 3 来运行 django 2,但似乎 uwsgi 运行 python 2.7.5
    • 不幸的是它没有。所以,我添加了一些关于我的问题的更多细节并更新了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2018-08-10
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    相关资源
    最近更新 更多