Django Apache:目标WSGI脚本不能作为Python模块加载

时间:2017-08-10 14:37:19

标签: python django apache mod-wsgi

我收到以下错误。我尝试了为同一错误提供的其他答案,但没有任何工作。任何帮助将不胜感激。

Apache错误日志:

[Thu Aug 10 19:51:22.397653 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Target WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py' cannot be loaded as Python module.
[Thu Aug 10 19:51:22.397731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Exception occurred processing WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py'.
[Thu Aug 10 19:51:22.398589 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] Traceback (most recent call last):
[Thu Aug 10 19:51:22.398657 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py", line 16, in <module>
[Thu Aug 10 19:51:22.398664 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     application = get_wsgi_application()
[Thu Aug 10 19:51:22.398675 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Aug 10 19:51:22.398680 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     django.setup(set_prefix=False)
[Thu Aug 10 19:51:22.398689 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
[Thu Aug 10 19:51:22.398694 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Aug 10 19:51:22.398703 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
[Thu Aug 10 19:51:22.398708 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     self._setup(name)
[Thu Aug 10 19:51:22.398717 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
[Thu Aug 10 19:51:22.398722 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     self._wrapped = Settings(settings_module)
[Thu Aug 10 19:51:22.398731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
[Thu Aug 10 19:51:22.398736 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Aug 10 19:51:22.398745 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "/home/sharan/myproject/myprojectenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Thu Aug 10 19:51:22.398749 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]     return _bootstrap._gcd_import(name[level:], package, level)
[Thu Aug 10 19:51:22.398758 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Aug 10 19:51:22.398776 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Aug 10 19:51:22.398786 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Thu Aug 10 19:51:22.398795 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Thu Aug 10 19:51:22.398864 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Aug 10 19:51:22.398879 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Aug 10 19:51:22.398889 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215]   File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Thu Aug 10 19:51:22.398913 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] ImportError: No module named 'proj_VivRx1'

Virtualhost文件(apache2 / sites-available / 000-default.conf)

ServerAdmin webmaster@localhost
DocumentRoot /home/sharan/myproject

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /static /home/sharan/myproject/proj_VivRx1/app_match/static
<Directory /home/sharan/myproject/proj_VivRx1/app_match/static>
    Require all granted
</Directory>

<Directory /home/sharan/myproject/proj_VivRx1/proj_VivRx1>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

<Directory /home/sharan/myproject/proj_VivRx1/proj_VivRx1>
    Require all granted
</Directory>

<Directory /home/sharan/myproject/proj_VivRx1>
    Require all granted
</Directory>

<Directory /home/sharan/myproject/myprojectenv>
    Require all granted
</Directory>

WSGIDaemonProcess myproject python-path=/home/sharan/myprojects python-home=/home/sharan/myproject/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py

WSGI文件(/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py):

import os,sys
sys.path.append('/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages')
sys.path.append('/home/sharan/myproject/proj_VivRx1')

from django.core.wsgi import get_wsgi_application



path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
    sys.path.append(path)

os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"

application = get_wsgi_application()

我尝试过玩弄地点。还检查了权限但没有用。 Apache版本是2.4.18。

1 个答案:

答案 0 :(得分:0)

*

[Thu Aug 10 19:51:22.397653 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Target WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py' cannot be loaded as Python module.
[Thu Aug 10 19:51:22.397731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Exception occurred processing WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py'.
[Thu Aug 10 19:51:22.398589 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] Traceback (most recent call last):

您的目录结构搞砸了。你有一个wsgi文件所在的目录混合,是在/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py中,因为虚拟主机设置为查找它...或者它是/ home / sharan /myproject/proj_VivRx1/wsgi.py?

您很可能需要调整文件夹路径以指向wsgi文件所在的正确位置。