如何让 apache 使用 python3.6 及其模块?
How to get apache to use python3.6 and its modules?
我有一个用 Flask 编写并为 python3.6 构建的网站。我正在尝试使用 Apache 部署我的网站,但遇到了问题。
我使用以下命令安装了 wsgi:
sudo apt-get install libapache2-mod-wsgi-py3
我安装 python3.6 使用:
sudo apt-get install python3.6
.
因为它是一个专用于这个单一站点的服务器,所以我使用 pip3.6 而不是在 virtualenv 中全局安装了我的 python 模块,所以我所有的 required/installed 模块都位于 /usr/local/lib/python3.6/dist-packages/
.
我还没弄清楚如何让 apache 使用 python3.6 及其模块。默认情况下,apache 用于服务的 python 版本是 3.5,系统默认 python3 版本(我通过在我的 .wsgi 文件中打印 sys.version_info
验证了这一点)。因此,我的 none 个模块在路径中。
环顾四周后,我发现了 apache 配置选项 WSGIPythonHome
和 WSGIPythonPath
。我尝试以不同的组合将这些添加到我的 apache.conf
,但没有任何效果。以下是我尝试过的以及错误是什么。
# /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
无论如何,我认为我在正确的轨道上,但无法弄清楚我做错了什么。似乎我没有使用正确的 PythonHome
,但我不确定如果不是上述之一,它应该是什么。
如有任何帮助,我们将不胜感激。
您不能强制为一个 Python 版本编译的 mod_wsgi 为不同的版本使用不同的 Python 安装。这是因为 mod_wsgi 实际上链接了 Python 库的编译版本,而不仅仅是 运行 某个任意版本的 python
程序。
你唯一能做的就是从系统包中卸载 mod_wsgi(它使用 Python 3.5)并自己从源代码安装 mod_wsgi 并针对 [=24= 进行编译] 3.6.
此外,您提供的 WSGIPythonHome
和 WSGIPythonPath
路径都不正确。当您从源代码安装 mod_wsgi 时,不要设置这些指令,因为它们会继续搞砸。
我有一个用 Flask 编写并为 python3.6 构建的网站。我正在尝试使用 Apache 部署我的网站,但遇到了问题。
我使用以下命令安装了 wsgi:
sudo apt-get install libapache2-mod-wsgi-py3
我安装 python3.6 使用:
sudo apt-get install python3.6
.
因为它是一个专用于这个单一站点的服务器,所以我使用 pip3.6 而不是在 virtualenv 中全局安装了我的 python 模块,所以我所有的 required/installed 模块都位于 /usr/local/lib/python3.6/dist-packages/
.
我还没弄清楚如何让 apache 使用 python3.6 及其模块。默认情况下,apache 用于服务的 python 版本是 3.5,系统默认 python3 版本(我通过在我的 .wsgi 文件中打印 sys.version_info
验证了这一点)。因此,我的 none 个模块在路径中。
环顾四周后,我发现了 apache 配置选项 WSGIPythonHome
和 WSGIPythonPath
。我尝试以不同的组合将这些添加到我的 apache.conf
,但没有任何效果。以下是我尝试过的以及错误是什么。
# /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
无论如何,我认为我在正确的轨道上,但无法弄清楚我做错了什么。似乎我没有使用正确的 PythonHome
,但我不确定如果不是上述之一,它应该是什么。
如有任何帮助,我们将不胜感激。
您不能强制为一个 Python 版本编译的 mod_wsgi 为不同的版本使用不同的 Python 安装。这是因为 mod_wsgi 实际上链接了 Python 库的编译版本,而不仅仅是 运行 某个任意版本的 python
程序。
你唯一能做的就是从系统包中卸载 mod_wsgi(它使用 Python 3.5)并自己从源代码安装 mod_wsgi 并针对 [=24= 进行编译] 3.6.
此外,您提供的 WSGIPythonHome
和 WSGIPythonPath
路径都不正确。当您从源代码安装 mod_wsgi 时,不要设置这些指令,因为它们会继续搞砸。