【问题标题】:How to fix "No module named 'encodings'" in Python3.7.1?如何修复 Python3.7.1 中的“No module named 'encodings'”?
【发布时间】:2020-01-02 23:32:20
【问题描述】:

我尝试为 myproject(mywords_dict) 启动 uwsgi:

uwsgi --http :8000  -H /root/mywords_dict/env --chdir mywords_dict -w mywords_dict.wsgi

但收到以下错误:

Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

我很困惑,如果我在进入虚拟环境后运行 uwsgi 可以正常工作。Python 版本的 'mywords_dict' 是 3.7.1。我检查了 mywords_dic/env 中是否有编码包。我可以从那里成功运行 python。有人可以帮忙吗?

*** Starting uWSGI 2.0.18 (64bit) on [Fri Aug 30 00:15:16 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-36) on 29 August 
2019 13:49:55
os: Linux-3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018
nodename: VM_0_17_centos
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /root
detected binary path: /root/.pyenv/versions/3.7.1/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
chdir() to mywords_dict
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3882
your memory page size is 4096 bytes
detected max file descriptor number: 100001
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 22645)
uwsgi socket 0 bound to TCP address 127.0.0.1:42301 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 3.7.1 (default, Nov 11 2018, 01:35:46)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
Set PythonHome to /root/mywords_dict/env
**Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'**

【问题讨论】:

  • Set PythonHome to /root/mywords_dict/env — 你真的在那个目录中安装了 Python 3 吗?你能从那里运行pythonimport encodings吗?
  • 您可能需要重新安装python或重置虚拟环境This might be a duplicate
  • @ryanyang,谢谢你的分享。但是我可以在不使用 uwsgi 的情况下在虚拟环境中成功运行 python 并导入编码。它是如此有线。
  • @SyntaxVoid 谢谢,但它对我不起作用。
  • 大家好,我终于通过 'rm -rf env' 解决了这个问题并重建了它。而且我仍然不知道为什么会这样。

标签: python-3.x uwsgi


【解决方案1】:

我遇到了同样的错误。 尝试这些步骤后修复:

  1. 以管理员身份卸载 python(38)。在自定义安装期间选中所有复选框,包括为所有用户安装和预编译标准库。
  2. 将 python38 降级到 37

虽然哈哈,但我仍然不知道错误是从哪里来的。

【讨论】:

    【解决方案2】:

    这是由于 python 虚拟环境路径错误。它在home 变量下的.ini 文件中定义。

    你需要做的是分配给这个指向你的venv的root的变量路径。因此,如果您的 venv 路径是 /home/user/project/venv,只需将此路径分配给 home 变量即可。确保在 venv 路径中包含尾随的 /(斜杠)(因为它稍后会连接到 /bin/python 并且最终会出现双斜杠。

    然后保存您的.ini 文件并尝试再次启动uWSGI。

    【讨论】:

    • 我犯了这个完全错误:我将 conf 中的 env 路径从 /home/vinzee/.pyenv/versions/envname/bin/ 更改为 /home/vinzee/.pyenv/versions/envname 并且它起作用了。
    猜你喜欢
    • 2020-04-23
    • 2019-07-02
    • 1970-01-01
    • 2023-03-15
    • 2018-10-26
    • 1970-01-01
    • 2011-01-20
    • 2021-06-04
    • 2022-11-11
    相关资源
    最近更新 更多