简体   繁体   English

目标 WSGI 脚本不能作为 python 模块加载

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

I have been trying to get my django app deployed for a while now and no matter what I have followed and tried I keep running into errors.我一直试图让我的 django 应用程序部署一段时间,无论我遵循什么并尝试过,我都会遇到错误。

I am currently getting this error:我目前收到此错误:

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

and

ModuleNotFoundError: No module named 'contextvars'

which is not something I used myself in my project.这不是我在我的项目中使用的东西。

I have tried some solutions like using:我尝试了一些解决方案,例如使用:

sudo chmod a+x wsgi.py

and trying libapache2-mod-wsgi-py3 vs libapache2-mod-wsgi并尝试 libapache2-mod-wsgi-py3 vs libapache2-mod-wsgi

my apache2.conf file where I placed my virtual host and the settings for my app:我的 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>

my wsgi.py file:我的 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()

This is my full apache error log from restarting the service and trying to access my website:这是我重新启动服务并尝试访问我的网站的完整 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'

You have configured Apache with python3.6 but run python3.10 in your virt.env (contextvars is part of python since version 3.7)您已经使用 python3.6 配置了 Apache,但在您的 virt.env 中运行了 python3.10(contextvars 是 python 自 3.7 版以来的一部分)

You should always run Apache with the same python version as in the virt.env您应该始终使用与 virt.env 中相同的 python 版本运行 Apache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将目标 WSGI 脚本加载为 Python 模块 - Target WSGI script cannot be loaded as Python module mod_wsgi目标WSGI脚本无法作为Python模块加载 - mod_wsgi Target WSGI script cannot be loaded as Python module 目标WSGI脚本wsgi.py&#39;无法作为Python模块加载 - Target WSGI script wsgi.py' cannot be loaded as Python module 无法将目标WSGI脚本作为Python模块+ ImportError加载:未命名模块 - Target WSGI script cannot be loaded as Python module + ImportError: No module named 目标 WSGI 脚本无法加载为 Python 模块 + 没有名为 Django 的模块 - Target WSGI script cannot be loaded as Python module + no module named Django 目标WSGI脚本无法作为Django App中的Python模块加载 - Target WSGI Script Cannot Be Loaded as Python Module in Django App 目标 WSGI 脚本无法加载为 Python 模块。Flask.Apache - Target WSGI script cannot be loaded as Python module.Flask.Apache 无法将目标WSGI脚本作为Python模块Raspberry Pi加载 - Target WSGI script cannot be loaded as Python module Raspberry Pi apache2 和 mod wsgi:目标 WSGI 脚本无法作为 Python 模块加载 - apache2 and mod wsgi : Target WSGI script cannot be loaded as Python module 目标WSGI脚本&#39;/home/ubuntu/Django/bot/wsgi.py&#39;无法作为Python模块加载 - Target WSGI script '/home/ubuntu/Django/bot/wsgi.py' cannot be loaded as Python module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM