Django WSGI 没有名为 'site' 的模块
Django WSGI No module named 'site'
我已经搜索、尝试并 运行 几乎所有可用的教程 运行 我的 django 应用程序与 apache 甚至 nginx(其中大部分都超过 3 或 4 岁)。
在我放弃之前,我已经设法完成并让所有的部分都可以与 nginx 一起工作,现在我正在尝试使用 apache2,到目前为止我遇到的唯一错误是 wsgi.py ,其他一切正常,但 运行ning
sudo python3 -i /var/www/shinra/shinra/wsgi.py
给我以下错误:
Traceback (most recent call last):
File "/var/www/shinra/shinra/wsgi.py", line 23, in <module>
application = get_wsgi_application()
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'shinra'
我的wsgi.py设置如下:
import os
import sys
PROJECT_DIR = '/var/www/shinra'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shinra.settings")
def execfile(filename):
globals = dict( __file__ = filename )
exec( open(filename).read(), globals )
activate_this = os.path.join( PROJECT_DIR, 'env/shinra/bin', 'activate_this.py' )
execfile( activate_this )
从django.core.wsgi导入get_wsgi_application
应用程序 = get_wsgi_application()
我也试过 运行 使用默认的 wsgi.py 设置它,但无济于事。
至于项目的其余部分,它只是一个 b运行d 的新 django 项目,除了将虚拟环境放入 /var/www/shinra/env/shinra/bin
之外,没有其他任何修改。谢谢,我已经为此奋斗了一段时间,而且我是 django 的新手。 运行 使用 apache2 显然会在 apache 日志中产生相同的错误。
编辑: 值得一提的是,我正在尝试 运行 在亚马逊网络服务 EC2 实例中
更新:
我尝试再次使用 gunicorn 从头开始做所有事情,到目前为止,如果我在我的虚拟环境中并且 运行
/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/scripts/gunicorn_config.py shinra.wsgi
但是如果我使用 supervisor 设置它,我会得到这个错误:
[2017-06-21 05:15:25 +0000] [10320] [INFO] Starting gunicorn 19.7.1
[2017-06-21 05:15:25 +0000] [10320] [INFO] Listening at: http://0.0.0.0:8000 (10320)
[2017-06-21 05:15:25 +0000] [10320] [INFO] Using worker: sync
[2017-06-21 05:15:25 +0000] [10323] [INFO] Booting worker with pid: 10323
[2017-06-21 05:15:25 +0000] [10323] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
__import__(module)
ImportError: No module named 'shinra'
[2017-06-21 05:15:25 +0000] [10323] [INFO] Worker exiting (pid: 10323)
[2017-06-21 05:15:25 +0000] [10320] [INFO] Shutting down: Master
[2017-06-21 05:15:25 +0000] [10320] [INFO] Reason: Worker failed to boot.
gunicorn 配置文件是:
command = '/home/ubuntu/venvs/shinra/bin/gunicorn'
pythonpath = '/home/ubuntu/venvs/shinra/bin/python'
bind = '0.0.0.0:8000'
workers = 3
我终于明白了!我的主管配置缺少一些参数:
[program:shinra_gunicorn]
command=/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/gunicorn_config.py shinra.wsgi
directory=/home/ubuntu/shinra
environment=PATH="/home/ubuntu/venvs/shinra/bin"
autostart=true
autorestart=true
stderr_logfile=/var/log/shinra.err.log
stdout_logfile=/var/log/shinra.out.log
我已经搜索、尝试并 运行 几乎所有可用的教程 运行 我的 django 应用程序与 apache 甚至 nginx(其中大部分都超过 3 或 4 岁)。
在我放弃之前,我已经设法完成并让所有的部分都可以与 nginx 一起工作,现在我正在尝试使用 apache2,到目前为止我遇到的唯一错误是 wsgi.py ,其他一切正常,但 运行ning
sudo python3 -i /var/www/shinra/shinra/wsgi.py
给我以下错误:
Traceback (most recent call last):
File "/var/www/shinra/shinra/wsgi.py", line 23, in <module>
application = get_wsgi_application()
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'shinra'
我的wsgi.py设置如下:
import os
import sys
PROJECT_DIR = '/var/www/shinra'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shinra.settings")
def execfile(filename):
globals = dict( __file__ = filename )
exec( open(filename).read(), globals )
activate_this = os.path.join( PROJECT_DIR, 'env/shinra/bin', 'activate_this.py' )
execfile( activate_this )
从django.core.wsgi导入get_wsgi_application 应用程序 = get_wsgi_application()
我也试过 运行 使用默认的 wsgi.py 设置它,但无济于事。
至于项目的其余部分,它只是一个 b运行d 的新 django 项目,除了将虚拟环境放入 /var/www/shinra/env/shinra/bin
之外,没有其他任何修改。谢谢,我已经为此奋斗了一段时间,而且我是 django 的新手。 运行 使用 apache2 显然会在 apache 日志中产生相同的错误。
编辑: 值得一提的是,我正在尝试 运行 在亚马逊网络服务 EC2 实例中
更新:
我尝试再次使用 gunicorn 从头开始做所有事情,到目前为止,如果我在我的虚拟环境中并且 运行
/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/scripts/gunicorn_config.py shinra.wsgi
但是如果我使用 supervisor 设置它,我会得到这个错误:
[2017-06-21 05:15:25 +0000] [10320] [INFO] Starting gunicorn 19.7.1
[2017-06-21 05:15:25 +0000] [10320] [INFO] Listening at: http://0.0.0.0:8000 (10320)
[2017-06-21 05:15:25 +0000] [10320] [INFO] Using worker: sync
[2017-06-21 05:15:25 +0000] [10323] [INFO] Booting worker with pid: 10323
[2017-06-21 05:15:25 +0000] [10323] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
__import__(module)
ImportError: No module named 'shinra'
[2017-06-21 05:15:25 +0000] [10323] [INFO] Worker exiting (pid: 10323)
[2017-06-21 05:15:25 +0000] [10320] [INFO] Shutting down: Master
[2017-06-21 05:15:25 +0000] [10320] [INFO] Reason: Worker failed to boot.
gunicorn 配置文件是:
command = '/home/ubuntu/venvs/shinra/bin/gunicorn'
pythonpath = '/home/ubuntu/venvs/shinra/bin/python'
bind = '0.0.0.0:8000'
workers = 3
我终于明白了!我的主管配置缺少一些参数:
[program:shinra_gunicorn]
command=/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/gunicorn_config.py shinra.wsgi
directory=/home/ubuntu/shinra
environment=PATH="/home/ubuntu/venvs/shinra/bin"
autostart=true
autorestart=true
stderr_logfile=/var/log/shinra.err.log
stdout_logfile=/var/log/shinra.out.log