在我的谷歌Compute Engine執行個體,我一直在試圖建立我的應用服務器(uWSGI)以下步驟:無法導入Django應用到uWSGI
- CD /路徑/到/項目/目錄
- workon virtual_env
- uwsgi --ini uwsgi.ini
我每次初始化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)中找到額外雙引號的任何實例。除此之外,我「M無法找到一個潛在的罪魁禍首,我認爲它或者是在我的.ini文件或安裝不正確一些第三方庫
‘畫中畫凍結’:
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 ***
這種額外的'「'故事看起來像[雙引號不正確的雙引號(http://stackoverflow.com/questions/43811318/unable- to-import-django-application-into-uwsgi),即'''而不是'''。即使顯然沒有,因爲你的追蹤確實展示了一個真正的雙引號。 – Kanak
看來我正確地使用了雙引號。我把它改成單引號和收到的錯誤: 導入錯誤:沒有名爲模塊「'adtor」 看起來好像多餘的單/雙引號無關,用它做 – QuintoViento
是您'os.environ.setdefault( 「DJANGO_SETTINGS_MODULE」,「adtor.settings」)'也正確寫入wsgi.py? – Kanak