首页 > 解决方案 > Nginx + uWSGI + django NoModuleFoundError: No module named 'saleor'

问题描述

Python 3.6.8 创建安装在 venv 中的 venv uwsgi 并正确符号链接并使用正确的 python 版本 nginx 安装系统范围

只是试图让最基本uwsgi --ini myinifile.ini的功能正常运行。

尽管尝试解决这个问题几天我总是回到这里,当我启动它时,我的 django 应用程序没有被 uwsgi 识别。

uwsgi 正常工作时uwsgi --uwsgi-file test.py --http-socket :8001

我可以python manage.py runserver 0.0.0.0:8001很好,django 在导航应用程序网站时以 0 权限问题启动应用程序。

我已经多次看到这个错误,我想我正在服用疯狂的药片并且错过了一些愚蠢而明显的东西。

[uWSGI] getting INI configuration from /home/saleor/saleor/saleor/wsgi/uwsgi.ini
[uwsgi-static] added mapping for /static => /app/static
*** Starting uWSGI 2.0.18 (64bit) on [Mon Nov 18 07:36:36 2019] ***
compiled with version: 7.4.0 on 18 November 2019 04:47:07
os: Linux-4.15.0 #1 SMP Thu Aug 23 19:33:51 MSK 2018
nodename: myurl.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/saleor/saleor/venv/bin
detected binary path: /home/saleor/saleor/venv/bin/uwsgi
chdir() to /home/saleor/saleor/saleor
your processes number limit is 62987
your memory page size is 4096 bytes
detected max file descriptor number: 1024
building mime-types dictionary from file /etc/mime.types...554 entry found
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :8001 fd 3
Python version: 3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]
PEP 405 virtualenv detected: /home/saleor/saleor/venv
Set PythonHome to /home/saleor/saleor/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x558314cc3dd0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145808 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
ModuleNotFoundError: No module named 'saleor'
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: 7969)
spawned uWSGI worker 1 (pid: 7970, cores: 1)
^CSIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
goodbye to uWSGI.  

这是我的 uwsgi.py 文件,名为:__init__.py

"""WSGI config for saleor project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""

from django.core.wsgi import get_wsgi_application

from saleor.wsgi.health_check import health_check

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saleor.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.

application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

application = health_check(application, "/health/")

这是我的 uwsgi.ini

[uwsgi]
die-on-term = true
http-socket = :$(PORT)
log-format = UWSGI uwsgi "%(method) %(uri) %(proto)" %(status) %(size) %(msecs)ms [PID:%(pid):Worker-%(wid)] [RSS:%(rssM)MB]
master = true
max-requests = 100
memory-report = true
module = saleor.wsgi:application
processes = 1
static-map = /static=/app/static
mimefile = /etc/mime.types
env = /home/saelor/saleor/venv
virtualenv = /home/saleor/saleor/venv
chdir = /home/saleor/saleor/saleor
master = true
vacuum = true
chmod-socket = 666
uid = saleor
gid = saleor

我只是想让 uwsgi 运行我的 saleor 应用程序,这样我就可以开始努力让它和 nginx 正常通信:( 我迷路了,我的大脑严重受伤。

标签: python-3.xnginxuwsgidjango-deployment

解决方案


  1. 更新到 python 3.8
  2. 在你的 venv 中安装 uwsgi
  3. uwsgi --http :8000 --module saleor.wsgi

不要触摸任何其他设置


推荐阅读