Apache如何使用Py2的Py3?

时间:2016-07-21 08:51:50

标签: python django apache mod-wsgi

Apache如何使用Python / 2.x中的Python / 3.x?

我现在正在尝试使用Py3在服务器上设置Django应用程序。 命令python manage.py runserver成功。 然后我尝试使用Apachemod_wsgi,但我得到Internal Server Error

错误日志说

[mpm_prefork:notice] [pid 30732] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations

但是默认的python是Py3。

# python -V
Python 3.5.1

我想知道当apache使用Py3时错误将被修复。你呢? 如何指定Py3?

启动命令

# /etc/init.d/httpd restart

完整错误日志

$ tailf  /etc/httpd/logs/error_log
[Thu Jul 21 15:32:20.626731 2016] [auth_digest:notice] [pid 30732] AH01757: generating secret for digest authentication ...
[Thu Jul 21 15:32:20.627378 2016] [lbmethod_heartbeat:notice] [pid 30732] AH02282: No slotmem from mod_heartmonitor
[Thu Jul 21 15:32:20.629557 2016] [mpm_prefork:notice] [pid 30732] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Thu Jul 21 15:32:20.629580 2016] [core:notice] [pid 30732] AH00094: Command line: '/usr/sbin/httpd'
[Thu Jul 21 15:37:31.940196 2016] [mpm_prefork:notice] [pid 30732] AH00169: caught SIGTERM, shutting down
[Thu Jul 21 15:37:31.981414 2016] [suexec:notice] [pid 30777] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jul 21 15:37:31.993034 2016] [auth_digest:notice] [pid 30778] AH01757: generating secret for digest authentication ...
[Thu Jul 21 15:37:31.993935 2016] [lbmethod_heartbeat:notice] [pid 30778] AH02282: No slotmem from mod_heartmonitor
[Thu Jul 21 15:37:31.996832 2016] [mpm_prefork:notice] [pid 30778] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Thu Jul 21 15:37:31.996866 2016] [core:notice] [pid 30778] AH00094: Command line: '/usr/sbin/httpd'

环境

Apache/2.4.6 (CentOS) 
mod_wsgi/3.4
Python 3.5.1
Django 1.9
CentOS 7.1

1 个答案:

答案 0 :(得分:1)

如果您正在使用已编译的 mod_wsgi ,则需要针对您要使用的版本针对相应的Python二进制文件对其进行编译,或者它默认为系统Python版本(不幸的是仍然是2.x)。例如:

wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz"
tar -xzf '4.4.21.tar.gz'
cd ./mod_wsgi-4.4.21
./configure --with-python=/usr/local/bin/python3.5
make
make install
祝你好运!