【问题标题】:Django Hosted on Apache: Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state:Django Hosted on Apache: Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state:
【发布时间】:2021-12-14 01:12:51
【问题描述】:

我正在尝试在 Apache 2.4 上托管一个 Django 应用程序。服务无法启动并产生以下错误

[Thu Oct 28 13:12:37.898096 2021] [mpm_winnt:notice] [pid 5144:tid 628] AH00418: Parent: Created child process 7828
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\apache24\\bin\\httpd.exe'
  sys.base_prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
  sys.base_exec_prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\apache24\\bin\\httpd.exe'
  sys.prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
  sys.exec_prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
  sys.path = [
    'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
    '.\\DLLs',
    '.\\lib',
    'C:\\apache24\\bin',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000fa0 (most recent call first):
  <no Python frame>
[Thu Oct 28 13:12:38.413708 2021] [mpm_winnt:crit] [pid 5144:tid 628] AH00419: master_main: create child process failed. Exiting.

服务器在我完成所有配置之前运行并进入“它工作”屏幕。

我认为这与我的 httpd-host conf 中的任何一个有关

<Directory /some/path/project>
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName localhost 
    WSGIPassAuthorization On
    ErrorLog "C:/Users/myuser/Desktop/app.error.log"
    CustomLog "C:/Users/myuser/Desktop/app.access.log"  combined
    WSGIScriptAlias /  "C:/Users/myuser/Desktop/app/wsgi_windows.py"
    <Directory "C:/Users/myuser/Desktop/app/EmployeeKiosk">
        <Files wsgi_windows.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static "C:/Users/myuser/Desktop/app/static"
    <Directory "C:/Users/myuser/Desktop/app/static">
        Require all granted
    </Directory>  
</VirtualHost>

或 我的 wsgi_windows py

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('C:/Users/myuser/Desktop/app/appEnv/Lib/site-packages')




# Add the app's directory to the PYTHONPATH
sys.path.append('C:/Users/myuser/Desktop/app')
sys.path.append('C:/Users/myuser/Desktop/app/appEnv')

os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

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

我使用的是虚拟环境,并没有很多关于如何处理的明确说明。

编辑:我应该提到这是一个 Windows 系统。根据https://code.google.com/archive/p/modwsgi/wikis/ConfigurationDirectives.wiki#WSGIPythonHome,您不能使用 WSGIPythonHome 覆盖 PYTHONEXECUTABLE 路径。但是,默认值应该是正确的,因为它与错误列表相匹配。

【问题讨论】:

    标签: python django apache


    【解决方案1】:

    好的,对于 Windows,您不需要使用 WSGIPythonHome。阿帕奇忽略了这一点。我必须做的是添加和环境变量 PYTHONHOME 并指向全局 python 目录 - 见下文:

    我重新加载了apache,它没有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      • 2022-12-26
      • 2022-12-02
      相关资源
      最近更新 更多