簡體   English   中英

目標 WSGI 腳本不能作為 python 模塊加載

[英]Target WSGI script cannot be loaded as a python module

我一直試圖讓我的 django 應用程序部署一段時間,無論我遵循什么並嘗試過,我都會遇到錯誤。

我目前收到此錯誤:

Target WSGI script '/home/brickmane/djangoapp/myserver/backend/core/wsgi.py' cannot be loaded as Python module.

ModuleNotFoundError: No module named 'contextvars'

這不是我在我的項目中使用的東西。

我嘗試了一些解決方案,例如使用:

sudo chmod a+x wsgi.py

並嘗試 libapache2-mod-wsgi-py3 vs libapache2-mod-wsgi

我的 apache2.conf 文件放置了我的虛擬主機和我的應用程序的設置:

WSGIPythonHome /home/brickmane/djangoapp/myserver/venv
WSGIPythonPath /home/brickmane/djangoapp/myserver/backend
<VirtualHost *:80>
  ServerAlias www.d8pricecheck.tk
  WSGIProcessGroup backend
  Alias /static/ /home/brickmane/djangoapp/myserver/backend/static/
  <Directory /home/brickmane/djangoapp/myserver/backend/static>
    Require all granted
  </Directory>
  WSGIScriptAlias / /home/brickmane/djangoapp/myserver/backend/core/wsgi.py
  <Directory /home/brickmane/djangoapp/myserver/backend/core>
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>
 WSGIDaemonProcess backend python-path=/home/brickmane/djangoapp/myserver/backend/core python-home=/home/brickmane/djangoapp/myserver/venv
 WSGIProcessGroup backend
</VirtualHost>

我的 wsgi.py 文件:

import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('/home/brickmane/djangoapp/myserver/backend/')

sys.path.append('/home/brickmane/djangoapp/myserver/backend/core/')
# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages')

# poiting to the project settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

這是我重新啟動服務並嘗試訪問我的網站的完整 apache 錯誤日志:

[Mon Jan 31 12:28:54.228176 2022] [mpm_prefork:notice] [pid 19551] AH00173: SIGHUP received.  Attempting to restart
[Mon Jan 31 12:28:54.292016 2022] [ssl:warn] [pid 19551] AH01916: Init: (brickmaneserver.comcast.net:443) You configured HTTP(80) on the standard HTTPS(443) port!
[Mon Jan 31 12:28:54.296542 2022] [mpm_prefork:notice] [pid 19551] AH00163: Apache/2.4.29 (Ubuntu) OpenSSL/1.1.1g mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Mon Jan 31 12:28:54.296588 2022] [core:notice] [pid 19551] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jan 31 12:29:00.082063 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436] mod_wsgi (pid=19618): Target WSGI script '/home/brickmane/djangoapp/myserver/backend/core/wsgi.py' cannot be loaded as Python module.
[Mon Jan 31 12:29:00.082120 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436] mod_wsgi (pid=19618): Exception occurred processing WSGI script '/home/brickmane/djangoapp/myserver/backend/core/wsgi.py'.
[Mon Jan 31 12:29:00.082830 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436] Traceback (most recent call last):
[Mon Jan 31 12:29:00.082874 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]   File "/home/brickmane/djangoapp/myserver/backend/core/wsgi.py", line 12, in <module>
[Mon Jan 31 12:29:00.082880 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]     from django.core.wsgi import get_wsgi_application
[Mon Jan 31 12:29:00.082890 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/core/wsgi.py", line 2, in <module>
[Mon Jan 31 12:29:00.082895 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]     from django.core.handlers.wsgi import WSGIHandler
[Mon Jan 31 12:29:00.082920 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 3, in <module>
[Mon Jan 31 12:29:00.082925 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]     from django.conf import settings
[Mon Jan 31 12:29:00.082933 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 19, in <module>
[Mon Jan 31 12:29:00.082938 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]     from django.utils.deprecation import RemovedInDjango50Warning
[Mon Jan 31 12:29:00.082946 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/utils/deprecation.py", line 5, in <module>
[Mon Jan 31 12:29:00.082951 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]     from asgiref.sync import sync_to_async
[Mon Jan 31 12:29:00.082959 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/asgiref/sync.py", line 2, in <module>
[Mon Jan 31 12:29:00.082963 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436]     import contextvars
[Mon Jan 31 12:29:00.082981 2022] [wsgi:error] [pid 19618] [remote 108.162.238.175:59436] ModuleNotFoundError: No module named 'contextvars'
[Mon Jan 31 12:29:00.343820 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614] mod_wsgi (pid=19618): Target WSGI script '/home/brickmane/djangoapp/myserver/backend/core/wsgi.py' cannot be loaded as Python module.
[Mon Jan 31 12:29:00.343880 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614] mod_wsgi (pid=19618): Exception occurred processing WSGI script '/home/brickmane/djangoapp/myserver/backend/core/wsgi.py'.
[Mon Jan 31 12:29:00.344018 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614] Traceback (most recent call last):
[Mon Jan 31 12:29:00.344063 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]   File "/home/brickmane/djangoapp/myserver/backend/core/wsgi.py", line 12, in <module>
[Mon Jan 31 12:29:00.344069 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]     from django.core.wsgi import get_wsgi_application
[Mon Jan 31 12:29:00.344079 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/core/wsgi.py", line 2, in <module>
[Mon Jan 31 12:29:00.344084 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]     from django.core.handlers.wsgi import WSGIHandler
[Mon Jan 31 12:29:00.344092 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 3, in <module>
[Mon Jan 31 12:29:00.344097 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]     from django.conf import settings
[Mon Jan 31 12:29:00.344105 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 19, in <module>
[Mon Jan 31 12:29:00.344109 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]     from django.utils.deprecation import RemovedInDjango50Warning
[Mon Jan 31 12:29:00.344117 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/django/utils/deprecation.py", line 5, in <module>
[Mon Jan 31 12:29:00.344122 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]     from asgiref.sync import sync_to_async
[Mon Jan 31 12:29:00.344130 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]   File "/home/brickmane/djangoapp/myserver/venv/lib/python3.10/site-packages/asgiref/sync.py", line 2, in <module>
[Mon Jan 31 12:29:00.344135 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614]     import contextvars
[Mon Jan 31 12:29:00.344164 2022] [wsgi:error] [pid 19618] [remote 162.158.187.159:38614] ModuleNotFoundError: No module named 'contextvars'

您已經使用 python3.6 配置了 Apache,但在您的 virt.env 中運行了 python3.10(contextvars 是 python 自 3.7 版以來的一部分)

您應該始終使用與 virt.env 中相同的 python 版本運行 Apache

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM