我想部署Django網站。它按預期在開發服務器上運行。 在cp虛擬環境下運行python時也導入成功。Django WSGI部署。不能導入名稱'SimpleCookie'
但在Apache的mod_wsgi我得到的folloing錯誤日誌的網站:
[Wed Jun 10 17:26:20.204238 2015] [:info] [pid 18376:tid 140307600816000] mod_wsgi (pid=18376): Attach interpreter ''.
[Wed Jun 10 17:26:47.476066 2015] [:info] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] mod_wsgi (pid=18377, process='', application='cp'): Loading WSGI script '/var/www/django_projects/cp/mysite/wsgi.py'.
[Wed Jun 10 17:26:47.575882 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] mod_wsgi (pid=18377): Target WSGI script '/var/www/django_projects/cp/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Jun 10 17:26:47.575951 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] mod_wsgi (pid=18377): Exception occurred processing WSGI script '/var/www/django_projects/cp/mysite/wsgi.py'.
[Wed Jun 10 17:26:47.575996 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] Traceback (most recent call last):
[Wed Jun 10 17:26:47.576201 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/django_projects/cp/mysite/wsgi.py", line 23, in <module>
[Wed Jun 10 17:26:47.576209 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] from django.core.wsgi import get_wsgi_application
[Wed Jun 10 17:26:47.576319 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/core/wsgi.py", line 2, in <module>
[Wed Jun 10 17:26:47.576327 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] from django.core.handlers.wsgi import WSGIHandler
[Wed Jun 10 17:26:47.576485 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 11, in <module>
[Wed Jun 10 17:26:47.576493 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] from django import http
[Wed Jun 10 17:26:47.576600 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/http/__init__.py", line 1, in <module>
[Wed Jun 10 17:26:47.576608 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] from django.http.cookie import SimpleCookie, parse_cookie
[Wed Jun 10 17:26:47.576738 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/http/cookie.py", line 7, in <module>
[Wed Jun 10 17:26:47.576746 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] from django.utils.six.moves import http_cookies
[Wed Jun 10 17:26:47.577075 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/utils/six.py", line 90, in __get__
[Wed Jun 10 17:26:47.577084 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] result = self._resolve()
[Wed Jun 10 17:26:47.577119 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/utils/six.py", line 113, in _resolve
[Wed Jun 10 17:26:47.577126 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] return _import_module(self.mod)
[Wed Jun 10 17:26:47.577156 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/utils/six.py", line 80, in _import_module
[Wed Jun 10 17:26:47.577163 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] __import__(name)
[Wed Jun 10 17:26:47.577193 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/http/__init__.py", line 1, in <module>
[Wed Jun 10 17:26:47.577200 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] from django.http.cookie import SimpleCookie, parse_cookie
[Wed Jun 10 17:26:47.577228 2015] [:error] [pid 18377:tid 140307470911232] [client 192.168.1.1:15841] ImportError: cannot import name 'SimpleCookie'
看來SimpleCookie的是進口做正確的第一次,但隨後拋出和錯誤。
我wsgi.py文件是:
import os
import sys
import site
sys.path.insert(0,'/var/www/.virtualenvs/cp/lib/python3.4/site-packages')
sys.path.insert(0, '/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django')
# Add the app's directory to the PYTHONPATH
sys.path.insert(0,'/var/www/django_projects/cp')
#sys.path.insert(0,'/var/www/django_projects/cp/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
編輯: 我不完全明白爲什麼,但除去
sys.path.insert(0, '/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django')
錯誤變化到另一個時:
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
似乎這解決了原來的錯誤,但提出了一個新的錯誤。
EDIT2: 我打過電話get_wsgi_application()之前添加
exec(open("/var/www/.virtualenvs/cp/bin/activate_this.py").read())
,但是這並沒有解決_sqlite3導入錯誤
關閉這個問題並打開新的新錯誤: Django WSGI deployment. No module named '_sqlite3'
您絕對不應該手動將網站包插入到sys.path中,甚至更不用說django子目錄。改用激活腳本。 –
我嘗試添加: EXEC(開放( 「/無功/網絡/ .virtualenvs/CP /斌/ activate_this.py」)閱讀()。) 和刪除 sys.path.insert(0,'/ var/www/.virtualenvs/cp/lib/python3.4/site-packages') sys.path.insert(0,'/var/www/.virtualenvs/cp/lib/python3.4/site-packages/ django') 但是出現錯誤沒有模塊名爲django: from django.core.wsgi import get_wsgi_application – Leo