如何让apache使用python3.6及其模块?

如何让apache使用python3.6及其模块?,apache,ubuntu,mod-wsgi,python-3.6,Apache,Ubuntu,Mod Wsgi,Python 3.6,我有一个网站写在烧瓶和python3.6建成。我正在尝试使用apache部署我的网站,但遇到了一些问题 我使用以下命令安装了wsgi: sudo apt get安装libapache2-mod-wsgi-py3 我使用以下方式安装了python3.6: sudoapt安装python3.6 因为它是一个专用于这个单一站点的服务器,所以我使用pip3.6全局安装了python模块,而不是在virtualenv中,所以我所有需要/安装的模块都位于/usr/local/lib/python3.6/di

我有一个网站写在烧瓶和python3.6建成。我正在尝试使用apache部署我的网站,但遇到了一些问题

我使用以下命令安装了wsgi: sudo apt get安装libapache2-mod-wsgi-py3

我使用以下方式安装了python3.6: sudoapt安装python3.6

因为它是一个专用于这个单一站点的服务器,所以我使用pip3.6全局安装了python模块,而不是在virtualenv中,所以我所有需要/安装的模块都位于/usr/local/lib/python3.6/dist packages/

我还没有弄明白如何让apache使用python3.6及其模块。默认情况下,apache用于服务的python版本是3.5,系统默认的python3版本是我通过在.wsgi文件中打印sys.version_信息来验证的。因此,路径中没有任何模块

环顾四周后,我找到了apache配置选项WSGIPythonHome和WSGIPythonPath。我尝试将这些添加到我的apache.confin不同的组合中,但没有任何效果。下面是我尝试的内容和错误

# /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'
不管怎么说,我认为我的思路是对的,但是我不知道我做错了什么。似乎我没有使用正确的PythonHome,但如果不是上面提到的一种,我不确定它应该是什么


任何帮助都将不胜感激。

您不能强制为一个Python版本编译的mod_wsgi为不同版本使用不同的Python安装。这是因为mod_wsgi实际上链接了它编译的版本的Python库,它不只是运行某个任意版本的Python程序

您唯一能做的就是从使用Python3.5的系统包中卸载mod_wsgi,自己从源代码中安装mod_wsgi,并根据Python3.6编译它


另外,您提供给WSGIPythonHome和WSGIPythonPath的路径都不正确。当您从源代码安装mod_wsgi时,不要设置这些指令,因为它们会继续把事情搞砸。

正是这样,谢谢。最后,我通过pip3.6安装了mod_wsgi,并告诉apache使用LoadModule wsgi_module/path/to/installed/so/file.so加载它。
# /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