无法将Django应用程序导入uWSGI

时间:2017-05-05 18:08:40

标签: django google-compute-engine uwsgi

在我的Google Compute Engine实例上,我一直在尝试按照以下步骤设置我的应用服务器(uWSGI):

  1. cd / path / to / project / directory
  2. workon virtual_env
  3. uwsgi --ini uwsgi.ini
  4. 每次初始化uWSGI时,都会抛出以下错误(下面有更广泛的日志):

    ImportError: No module named '"adtor'
    unable to load app 0 (mountpoint='') (callable not found or import error)
    

    我能够单独运行开发服务器(python manage.py runserver)。特殊情况是在我的django应用程序名称之前有一个额外的双引号(")但是我无法在代码中找到任何额外双引号的实例,.ini,虚拟env钩子(例如postactivate)。除此之外,我无法找到潜在的罪魁祸首;我假设它在我的.ini文件中或未正确安装某些第三方库。

    " pip freeze":

    appdirs==1.4.3
    Django==1.8.5
    django-filter==1.0.2
    django-model-utils==3.0.0
    djangorestframework==3.6.2
    mysqlclient==1.3.10
    packaging==16.8
    pyparsing==2.2.0
    six==1.10.0
    uWSGI==2.0.15
    

    uwsgi.ini

    [uwsgi]
    socket=127.0.0.1:8000
    stats=127.0.0.1:9191
    http-timeout=1800
    
    uid=www-data
    gid=www-data
    
    virtualenv=/home/tor/.virtualenvs/adtor_prod
    home=/home/tor/.virtualenvs/adtor_prod
    chdir=/srv/django/adtor_project/prime
    module=adtor.wsgi:application
    master=true
    vacuum=true
    thunder-lock=true
    pidfile=/tmp/project-master.pid
    daemonize=/var/log/uwsgi/adtor-blog.log
    
    threads=2
    enable-threads=true
    
    for-readline = /etc/srv/vars.txt
      env = %(_)
    endfor =
    

    日志:

    *** Starting uWSGI 2.0.15 (64bit) on [Fri May  5 16:00:56 2017] ***
    compiled with version: 4.8.4 on 02 May 2017 17:47:17
    os: Linux-4.4.0-75-generic #96~14.04.1-Ubuntu SMP Thu Apr 20 11:06:30 UTC 2017
    nodename: instance-1
    machine: x86_64
    clock source: unix
    detected number of CPU cores: 1
    current working directory: /srv/django/adtor_project
    writing pidfile to /tmp/project-master.pid
    detected binary path: /home/tor/.virtualenvs/adtor_prod/bin/uwsgi
    !!! no internal routing support, rebuild with pcre support !!!
    chdir() to /srv/django/adtor_project/prime
    your processes number limit is 2257
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    thunder lock: enabled
    uwsgi socket 0 bound to TCP address 127.0.0.1:8000 fd 3
    Python version: 3.4.3 (default, Nov 17 2016, 01:12:14)  [GCC 4.8.4]
    Set PythonHome to /home/tor/.virtualenvs/adtor_prod
    Python main interpreter initialized at 0x1a02ab0
    python threads support enabled
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 166112 bytes (162 KB) for 2 cores
    *** Operational MODE: threaded ***
    Traceback (most recent call last):
      File "./adtor/wsgi.py", line 16, in <module>
        application = get_wsgi_application()
      File "/home/tor/.virtualenvs/adtor_prod/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
        django.setup()
      File "/home/tor/.virtualenvs/adtor_prod/lib/python3.4/site-packages/django/__init__.py", line 17, in setup
        configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
      File "/home/tor/.virtualenvs/adtor_prod/lib/python3.4/site-packages/django/conf/__init__.py", line 48, in __getattr__
        self._setup(name)
      File "/home/tor/.virtualenvs/adtor_prod/lib/python3.4/site-packages/django/conf/__init__.py", line 44, in _setup
        self._wrapped = Settings(settings_module)
      File "/home/tor/.virtualenvs/adtor_prod/lib/python3.4/site-packages/django/conf/__init__.py", line 92, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/home/tor/.virtualenvs/adtor_prod/lib/python3.4/importlib/__init__.py", line 109, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ImportError: No module named '"adtor'
    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: 8753)
    spawned uWSGI worker 1 (pid: 8755, cores: 2)
    *** Stats server enabled on 127.0.0.1:9191 fd: 10 ***
    

2 个答案:

答案 0 :(得分:0)

这可能不是答案,但是:请注意,如果您的路径不是文件或目录,则不会使用尾部斜杠。话虽这么说,让我们尝试考虑你的目录:

[uwsgi]
...
virtualenv=/home/tor/.virtualenvs/adtor_prod/
home=/home/tor/.virtualenvs/adtor_prod/
chdir=/srv/django/adtor_project/prime/
...

您也可以尝试在module=adtor.wsgi:application

下面添加此行
...
module=adtor.wsgi:application
env DJANGO_SETTINGS_MODULE=adtor.settings
...

答案 1 :(得分:0)

在我的uwsgi.ini文件中,我从另一个文件中错误地加载了设置模块。而不是

env = DJANGO_SETTINGS_MODULE='adtor.settings.production'

我用过

env = DJANGO_SETTINGS_MODULE=adtor.settings.production