python - 尝试启动 uwsgi 时出现致命的 Python 错误 : init_fs_encoding: failed to get the Python codec of the filesystem encoding,

标签 python django ubuntu uwsgi

我试图在我的虚拟环境中启动我的 uwsgi 服务器,但是在我添加了 plugin python3 之后选项我每次都会收到此错误:

!!! Python Home is not a directory: /home/env3/educ !!!
Set PythonHome to /home/env3/educ
Python path configuration:
  PYTHONHOME = '/home/env3/educ'
  PYTHONPATH = (not set)
  program name = '/home/env3/educ/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/home/env3/educ/bin/python'
  sys.base_prefix = '/home/env3/educ'
  sys.base_exec_prefix = '/home/env3/educ'
  sys.executable = '/home/env3/educ/bin/python'
  sys.prefix = '/home/env3/educ'
  sys.exec_prefix = '/home/env3/educ'
  sys.path = [
    '/home/env3/educ/lib/python38.zip',
    '/home/env3/educ/lib/python3.8',
    '/home/env3/educ/lib/python3.8/lib-dynload',
  ]
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 0x00007efe89db8780 (most recent call first):
<no Python frame>
我还尝试使用 python3 -m venv env 创建新的虚拟环境并将项目文件移动到它,但仍然是同样的错误。
这是我的 uwsgi.ini 文件:
[uwsgi]

base = /home/env3/educ
projectname = educ

plugins = python3
master = true
virtualenv = /home/env3/%(projectname)
pythonpath = %(base)
env = DJANGO_SETTINGS_MODULE=%(projectname).settings.pro
module = %(projectname).wsgi:application
socket = /tmp/%(projectname).sock
chmod-socket = 666
我使用 Python 3.8.5
我正在尝试使用 Django + uWSGI + nginx + Postgresql。

最佳答案

我看到你的 PYTHONHOME 设置为 PYTHONHOME = '/home/env3/educ' .尝试检查它是否真的存在。
解决方案对我来说是 删除 PYTHONHOME环境变量 .
对您来说,可以是这样,或者将该变量设置为另一个值。
这适用于 Windows,并且肯定适用于 Linux。如果有人尝试这样做,请在此处发表评论!
一位 CPython 开发人员确认了解决方案 here. :

This is not a Python bug, this is a symptom of setting PYTHONHOME and/or PYTHONPATH when they’re not needed. In nearly all cases you don’t need to set either of them;

In the case of PYTHONHOME it’s almost always a mistake to set.

关于python - 尝试启动 uwsgi 时出现致命的 Python 错误 : init_fs_encoding: failed to get the Python codec of the filesystem encoding,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65184937/

相关文章:

java - 尝试写入文件时 Tomcat 权限被拒绝

python - Tastypie - 未找到嵌套资源字段

python - 如何根据焦点设置Kivy TextInput背景颜色

python - Django 表单不渲染小部件

python - jinja2 中的标签中是否有相当于 "blocktrans"的内容?

django - CSRF验证失败,但仅限于Facebook App

python - 如何将字符串转换为 float ?

python - 将代码移出 __init__.py 但保持向后兼容性

ubuntu - 在 Ubuntu 20.04 上安装 Redhawk 尝试启动 OmniOrb 服务但失败并出现以下错误 :

Linux命令用重定向输出的文本替换文件中的文本