【问题标题】:OSX/Apache ModuleNotFoundError: No module named 'encodings'OSX/Apache ModuleNotFoundError:没有名为“编码”的模块
【发布时间】:2018-03-08 08:56:26
【问题描述】:

我有一个本地 Django 应用程序,我已经开发了一段时间。今天,在停止工作大约一个月后,我又回到了它,但它不会加载。检查 apache 错误日志,我一遍又一遍地看到以下内容:

Current thread 0x00007fffc0be23c0 (most recent call first):
[Tue Sep 26 19:18:09.154141 2017] [core:notice] [pid 1590] AH00052: child pid 1651 exit signal Abort trap (6)
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

上次我在做这个项目时,我对我的项目代码做了一些更改,但没有触及我的 apache 或 mod_wsgi 配置。

我的 PYTHONPATH 未设置(一个月前一切正常时也未设置。这是我的 mod_wsgi 配置(同样没有更改):

WSGIDaemonProcess secureDash python-path=/Users/user/projects/secureDash_project python-home=/Users/user/.venvs/securedash_py3.6
WSGIProcessGroup secureDash
WSGIScriptAlias / /Users/user/projects/secureDash_project/config/wsgi.py

我花了很多时间在谷歌上搜索这个问题,但似乎没有一个常见的修复方法适用。寻找有关其他地方的指导。

【问题讨论】:

  • 您是否删除了它正在使用的 Python 虚拟环境?路径/Users/user/.venvs/securedash_py3.6 存在吗?
  • 我没有删除它。 workon securedash_py3.6 仍然有效,并且从该 venv which python 返回 /Users/user/.venvs/securedash_py3.6/bin/python
  • 刚刚注意到,在我的 venv 内部,如果我尝试打开 python 控制台,我会收到以下错误:dyld: Library not loaded: @executable_path/../.Python Referenced from: /Users/user/.venvs/securedash_py3.6/bin/python Reason: image not found Abort trap: 6 搜索指向我这个 SO 帖子:stackoverflow.com/questions/23233252/… 所以我我会深入研究,但我有预感这就是问题所在
  • 创建 virtualenv 的 Python 安装可能已被删除。确定您是否仍然安装了原始 Python 3.6,销毁并使用它重新创建 Python virtualenv。
  • 我已经通过自制软件安装了 python 3.6,并且必须运行 brew cleanup 做一些其他的事情,并且 virtualenv 中的符号链接被破坏了

标签: django macos apache python-3.x mod-wsgi


【解决方案1】:

我发现,在我的 virtualenv 中:

workon securedash_py3.6

尝试运行 python 控制台时出错:

(securedash_py3.6) user conf $ python3
dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/user/.venvs/securedash_py3.6/bin/python3
  Reason: image not found
Abort trap: 6

搜索该错误将我指向this SO 主题,该主题最终解决了我的问题。基本上我用自制软件做了一些东西,这些东西一定破坏了我的 venv 中的符号链接。以下是我阅读要解决的具体命令:

find ~/.venvs/securedash_py3.6/ -type l -delete

然后 cd 到 virtualenv 目录:

$ cd ~/.venvs/securedash_py3.6
$ virtualenv .
Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6'
Overwriting /Users/user/.venvs/securedash_py3.6/lib/python3.6/orig-prefix.txt with new content
New python executable in /Users/user/.venvs/securedash_py3.6/bin/python3.6
Also creating executable in /Users/user/.venvs/securedash_py3.6/bin/python
Installing setuptools, pip, wheel...done.

一切都很好。

【讨论】:

    猜你喜欢
    • 2017-08-15
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2020-04-01
    • 2019-03-28
    • 2019-05-31
    • 2022-01-07
    相关资源
    最近更新 更多