1

I have a local Django application that I've been developing for a while. Today, after about a month off from working on it I went back to it, but it wouldn't load. Checking the apache error log, I see the following over and over:

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'

The last time I was working on the project, I made some changes to my project code, but didn't touch and of my apache or mod_wsgi configuration.

My PYTHONPATH is not set (nor was it set a month ago when everything was working. Here's my mod_wsgi configs (again haven't changed):

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

I've spent a lot of time googling this issue, but none of the common fixes seem to apply. Looking for some guidance on where else to look.

brewcrazy
  • 623
  • 13
  • 30
  • Did you delete the Python virtual environment it is using? Does the path ``/Users/user/.venvs/securedash_py3.6`` exist? – Graham Dumpleton Sep 27 '17 at 01:50
  • I did not delete it. `workon securedash_py3.6` still works and from that venv `which python` returns `/Users/user/.venvs/securedash_py3.6/bin/python` – brewcrazy Sep 27 '17 at 01:54
  • Just noticed that, inside of my venv, if I attempt to open the python console I get the following error: `dyld: Library not loaded: @executable_path/../.Python Referenced from: /Users/user/.venvs/securedash_py3.6/bin/python Reason: image not found Abort trap: 6` searching on that points me to this SO post: https://stackoverflow.com/questions/23233252/broken-references-in-virtualenvs so I'm going to dig into that, but I have a hunch that's the issue – brewcrazy Sep 27 '17 at 01:57
  • The Python installation that the virtualenv was created from was likely deleted. Work out if you still have original Python 3.6 installed, destroy and then recreate the Python virtualenv using it. – Graham Dumpleton Sep 27 '17 at 02:17
  • I had installed python 3.6 via homebrew and must have ran `brew cleanup` doing some other stuff and the symlinks in the virtualenv were broken – brewcrazy Sep 27 '17 at 02:20

1 Answers1

1

I discovered that, while in my virtualenv:

workon securedash_py3.6

I got an error trying to run the python console:

(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

Searching that error pointed me to this SO topic that eventually resolved my issue. Basically I had done some stuff with homebrew that must have broken the symlinks in my venv. Here are the specific commands that I read to resolve:

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

Then cd to the virtualenv directory:

$ 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.

And all is well.

brewcrazy
  • 623
  • 13
  • 30