【问题标题】:uWSGI Fatal Python error: Py_Initialize: Unable to get the locale encodinguWSGI 致命 Python 错误:Py_Initialize:无法获取语言环境编码
【发布时间】:2014-01-16 15:20:27
【问题描述】:

我已经看到至少 3 个关于这个问题的问题。

  1. 虚拟环境 (Python 3.2)
  2. 此环境中的 Django 项目
  3. uWSGI

但我在 uWSGI 设置文件中有plugins = python3,没关系!
服务器已启动,一切正常...
重新启动服务器 - 一切仍然正常...
重新加载服务器(或touch reload-file),您会遇到以下错误:

Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings

更多...我在另一个环境中有另一个项目,touch reload-file 为它工作。
有什么建议为什么会发生这种情况?

PS:我尝试创建一个新的 virtualenv

日志:

service uwsgi restart之后:

...
Sun Dec 29 22:57:21 2013 - detected max file descriptor number: 1024
Sun Dec 29 22:57:21 2013 - lock engine: pthread robust mutexes
Sun Dec 29 22:57:21 2013 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/test/socket fd 3
Sun Dec 29 22:52:59 2013 - uwsgi socket 1 bound to TCP address 127.0.0.1:3045 fd 5
Sun Dec 29 22:52:59 2013 - Python version: 3.2.3 (default, Sep 25 2013, 19:38:45)  [GCC 4.7.2]
Sun Dec 29 22:52:59 2013 - Set PythonHome to /pyenvs/test/
Sun Dec 29 22:52:59 2013 - Python main interpreter initialized at 0x688cc0
Sun Dec 29 22:52:59 2013 - threads support enabled
Sun Dec 29 22:52:59 2013 - your server socket listen backlog is limited to 10000 connections
Sun Dec 29 22:52:59 2013 - *** Operational MODE: preforking ***
Sun Dec 29 22:52:59 2013 - WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x688cc0 pid: 1619 (default app)
Sun Dec 29 22:52:59 2013 - *** uWSGI is running in multiple interpreter mode ***
Sun Dec 29 22:52:59 2013 - spawned uWSGI master process (pid: 1619)
Sun Dec 29 22:52:59 2013 - spawned uWSGI worker 1 (pid: 1628, cores: 1)
Sun Dec 29 22:52:59 2013 - spawned uWSGI worker 2 (pid: 1629, cores: 1)

service uwsgi reload之后:

Sun Dec 29 22:55:31 2013 - *** Starting uWSGI 1.2.3-debian (64bit) on [Sun Dec 29 22:55:31 2013] ***
...
Sun Dec 29 22:55:31 2013 - detected max file descriptor number: 1024
Sun Dec 29 22:55:31 2013 - lock engine: pthread robust mutexes
Sun Dec 29 22:55:31 2013 - uwsgi socket 0 inherited UNIX address /run/uwsgi/app/test/socket fd 3
Sun Dec 29 22:55:31 2013 - uwsgi socket 1 inherited INET address 127.0.0.1:3045 fd 5
Sun Dec 29 22:55:31 2013 - Python version: 3.2.3 (default, Sep 25 2013, 19:38:45)  [GCC 4.7.2]
Sun Dec 29 22:55:31 2013 - Set PythonHome to /pyenvs/test/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings

更新 1

这绝对是虚拟环境。复制我的旧 VEnv 并使用不会导致此问题。
仍然不知道为什么新创建的不起作用。
仅复制 python 可执行文件没有帮助。

【问题讨论】:

  • 请添加 uWSGI 启动日志,因为它们会报告真正使用了哪个版本的 python 以及 venv 是否正常
  • 已添加,@roberto。我不明白的是为什么它可以工作但不能只是重新加载。
  • 1.2.3 来自 2 年多前。更新它有已知的错误,它来自 uWSGI 用户群不像现在那么大的时候。也许它与您的具体问题无关,但最好尝试一下。
  • 你是如何安装 uwsgi 的?
  • 是Ubuntu 12.10的系统包

标签: python uwsgi


【解决方案1】:

我不知道到底发生了什么,因为我做了很多事情:

  1. 系统升级
  2. 新的 python 环境
  3. Python 版本 3.3,而不是 3.2
  4. uwsgi 1.2.4 系统包(或许有帮助)
    或者更好地在你的 VE 中使用 pip install uwsgi 并使用 supervisord 运行你需要的东西

现在它正在工作。谢谢罗伯特。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 2019-08-31
    • 2020-03-09
    • 2013-05-06
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多