2

I have a website written in flask and built for python3.6. I am trying to deploy my website using apache and have been having issues.

I installed wsgi using the command: sudo apt-get install libapache2-mod-wsgi-py3

I installed python3.6 using: sudo apt-get install python3.6.

Because it is a server dedicated to just this single site I installed my python modules globally using pip3.6 instead of in a virtualenv so all my required/installed modules are located at /usr/local/lib/python3.6/dist-packages/.

I haven't been able to figure out how to get apache to use python3.6 and its modules. By default the version of python apache is using to serve is 3.5, the systems default python3 version (I verified this by printing sys.version_info in my .wsgi file). Because of this it none of my modules are in the path.

After looking around I found the apache config options WSGIPythonHome and WSGIPythonPath. I have tried adding these to my apache.confin different combinations but nothing has worked. Below is what I tried and what the errors were.

# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6

# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
WSGIPythonPath /usr/local/lib/python3.6

# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/
WSGIPythonPath /usr/local/lib/python3.6

# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
WSGIPythonPath /usr/local/lib/python3.6

# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
WSGIPythonPath /usr/local/lib/python3.6/dist-packages

# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

# /etc/apache2/apache.conf
WSGIPythonPath /usr/local/lib/python3.6

# /var/log/apache2/error.log
Using python version 3.5
Module flask not found

# /etc/apache2/apache.conf
WSGIPythonPath /usr/local/lib/python3.6/dist-packages

# /var/log/apache2/error.log
Using python version 3.5
Module flask not found

Anyway, I think I'm on the right track but can not figure out quite what I am doing wrong. It seems that I am not using the correct PythonHome but I'm not sure what it should be if not one of the above.

Any help would be greatly appreciated.

1 Answer 1

4

You can't force mod_wsgi compiled for one Python version to use a different Python installation for a different version. This is because mod_wsgi actually links the Python library for the version it was compiled for, it doesn't just run the python program of some arbitrary version.

The only thing you can do is uninstall mod_wsgi from system packages (which uses Python 3.5) and install mod_wsgi from source code yourself and compile it against Python 3.6.

Also, neither of the paths you gave WSGIPythonHome and WSGIPythonPath were correct anyway. When you install mod_wsgi from source code, don't set those directives as they will continue to screw things up.

1
  • 1
    This was exactly it, thank you. I ended up installing mod_wsgi through pip3.6 and telling apache to load it using: LoadModule wsgi_module /path/to/installed/so/file.so.
    – blitz1616
    Commented Jan 20, 2018 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.