【发布时间】:2014-05-31 16:20:28
【问题描述】:
环境:
- Mac OS X 10.8.5
- Apache2(操作系统自带的版本)
- Python2(操作系统自带的版本)
- Python3(通过 Homebrew 安装)
此代码在网络浏览器中返回“测试”:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from __future__ import print_function, division
print("Content-Type: text/html") # HTML is following.
print() # Blank line, end of headers.
print("testing")
但是这段代码在网络浏览器中返回“Internal Server Error”(这次使用python3):
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
print("Content-Type: text/html") # HTML is following.
print() # Blank line, end of headers.
print("testing")
...在 Apache2 错误日志中:
env: python3: No such file or directory
Premature end of script headers: test_cgi.py
在echo $PATH:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
看得更深,ls -al /usr/bin/python*:
/usr/bin/python
/usr/bin/python-config
/usr/bin/python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
/usr/bin/python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
/usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
/usr/bin/python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
/usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
/usr/bin/pythonw
/usr/bin/pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
/usr/bin/pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
/usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
在ls -al /usr/local/bin/python*:
/usr/local/bin/python3 -> ../Cellar/python3/3.3.3/bin/python3
/usr/local/bin/python3.3 -> ../Cellar/python3/3.3.3/bin/python3.3
/usr/local/bin/python3.3-config -> ../Cellar/python3/3.3.3/bin/python3.3-config
/usr/local/bin/pythonw3.3 -> ../Cellar/python3/3.3.3/bin/pythonw3.3
问题:
- 既然我的 PATH 中的第一项是 /usr/local/bin,为什么 Apache 找不到 Python3?
- 如何让 Apache 使用 Python3?
感谢您的帮助:)
【问题讨论】:
标签: apache python-3.x osx-mountain-lion homebrew