OSX/Apache ModuleNotFoundError: No module named 'encodings'

OSX/Apache ModuleNotFoundError: No module named 'encodings'

我有一个我已经开发了一段时间的本地 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

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

我发现,在我的 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.

一切都很好。