【问题标题】:Django + uwsgi + nginx . Import error: No module named pyDjango + uwsgi + nginx 。导入错误:没有名为 py 的模块
【发布时间】:2013-10-22 12:18:18
【问题描述】:

我正在尝试使用 uWSGI 和 nginx 运行我的示例 django 应用程序。但是我收到了导入错误,没有名为 py 的模块。我不确定应该在哪里添加 python 路径。

我正在使用以下命令运行。

sudo uwsgi --socket mysite.socket --module wsgi.py --chmod-socket=666. 

我什至尝试在参数--pythonpath 中传递路径,仍然是同样的错误。

这就是我的 wsgi.py 的样子

enter code here

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

当我尝试跑步时,我收到以下消息

ubuntu@ubuntu1204desktopi386:/usr/local/lib/python2.7/site-packages/mysite/mysite
$ sudo uwsgi --socket mysite.socket --module wsgi.py --chmod-socket=666 
*** Starting uWSGI 1.9.18.1 (32bit) on [Mon Oct 14 13:15:19 2013] ***
compiled with version: 4.6.3 on 13 October 2013 02:53:51
os: Linux-3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:15:33 UTC 2013
nodename: ubuntu1204desktopi386
machine: i686
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /usr/local/lib/python2.7/site-packages/mysite/mysite
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3846
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 mysite.socket fd 3
Python version: 2.7.3 (default, Sep 26 2013, 20:26:19)  [GCC 4.6.3]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x9644d68
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 64024 bytes (62 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named py
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: 2311, cores: 1)

【问题讨论】:

  • 在您的任何文件中,您是否做过类似import something.py 的操作?
  • 没有。这是因为我为--module wsgi.py 传递了一个python 文件。它应该只是一个模块,--module wsgi

标签: python django nginx


【解决方案1】:

如果python manage.py runserver 0.0.0.0:8024可以正常工作,那么

这也可以工作(在与上述命令相同的目录中运行):

uwsgi --http :8024 --module mysite.wsgi

mysite是这个django项目的名字

uwsgi 版本为2.0.14; django 版本是1.10

参考:https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

【讨论】:

    【解决方案2】:

    我猜你也可以像这样使用 --wsgi-file wsgi.py

     $ uwsgi --socket 127.0.0.1:8000 --wsgi-file my_proj/wsgi.py
    

    确保从同一文件夹运行命令

    【讨论】:

      【解决方案3】:

      --module 参数可能是 Python 模块,而不是文件。所以你可能只需要--module=wsgi

      【讨论】:

        猜你喜欢
        • 2012-02-28
        • 1970-01-01
        • 2017-03-13
        • 2021-04-27
        • 2012-03-16
        • 1970-01-01
        • 1970-01-01
        • 2012-10-26
        相关资源
        最近更新 更多