【问题标题】:ERROR: No module named 'encodings' when deploying django using wsgi on amazon linux 2错误:在 amazon linux 2 上使用 wsgi 部署 django 时没有名为“encodings”的模块
【发布时间】:2021-08-03 14:04:57
【问题描述】:

在过去的几天里,我一直在参考 Stackoverflow 来解决我的问题。 我在 Amazon Linux 2 上使用 WSGI 托管 Django 应用程序。我在这里将 pyenv 用于多个 python 版本。而python版本是3.7.10。下面是我的 Apache Conf 和 wsgi.py。

# WSGI config for mysite project.
# 
# It exposes the WSGI callable as a module-level variable named
# ``application``.
# 
# For more information on this file, see
# https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ """

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()
<VirtualHost *:80>
        ServerName wsgi.iamvishnu.xyz
        #DocumentRoot /var/www/html
        #for django
        LoadModule wsgi_module modules/mod_wsgi_python3.so



Alias /static/ /home/mod-wsgi/mysite/static/
        <Directory /home/mod-wsgi/mysite>
                Require all granted
        </Directory>

        <Directory /home/mod-wsgi/mysite/mysite>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

WSGIDaemonProcess mysite user=mod-wsgi2 group=mod-wsgi2
python-path=/home/mod-wsgi2:/home/mod-wsgi2/mysite:/home/mod-wsgi2/mysite/mysite:/home/mod-wsgi2/.pyenv/versions/3.6.8/envs/virtual/lib/python3.6/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /home/mod-wsgi2/mysite/mysite/wsgi.py

下面是我从 apache 错误日志中得到的错误

Current thread 0x00007fd4b2087240 (most recent call first): [Tue Aug
03 05:27:15.145298 2021] [core:notice] [pid 24159] AH00052: child pid
24229 exit signal Aborted (6) Fatal Python error: initfsencoding:
unable to load the file system codec ModuleNotFoundError: No module
named 'encodings'

Current thread 0x00007fd4b2087240 (most recent call first): [Tue Aug
03 05:27:16.147167 2021] [core:notice] [pid 24159] AH00052: child pid
24230 exit signal Aborted (6) Fatal Python error: initfsencoding:
unable to load the file system codec ModuleNotFoundError: No module
named 'encodings'

Current thread 0x00007fd4b2087240 (most recent call first): [Tue Aug
03 05:27:17.149010 2021] [core:notice] [pid 24159] AH00052: child pid
24231 exit signal Aborted (6) Fatal Python error: initfsencoding:
unable to load the file system codec ModuleNotFoundError: No module
named 'encodings'

谁能告诉我我在这里错过了什么。如果需要,我将提供有关相同的更多信息。您能提供的任何帮助将不胜感激。

【问题讨论】:

标签: python django devops wsgi


【解决方案1】:
  1. 同时定义了 PYTHON_HOME=virtual_env_path 和 PYTHON_PATH=/home/mod-wsgi/mysite。
  2. 确保 venv python 版本与您编写代码时使用的版本相同。

【讨论】:

  • 我已经使用 pip 安装了最新版本的 mod-wsgi
  • 并将以下内容添加到我的 wsgi.conf 中。这解决了我的问题。 LoadModule wsgi_module /usr/local/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so
猜你喜欢
  • 2015-08-26
  • 2023-04-08
  • 1970-01-01
  • 2018-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-07
  • 2022-12-18
相关资源
最近更新 更多