提示:
1: 2.6.4, 2.6.5 都有hashlib.py的bug,都可以用下面提到的patch修复
2: 在安装好的,记得ldconfig
3: 在安装mod_python时(3.3.1),记得修复connobject.c的bug
4: 如果是用于apache,请不要使用python2.7,python3以上,现在mod_python还不支持,会造成下面提到的安装好后apache报错
5: 所有bug都请在configure前修复
安装
1: ./configure --prefix=/program2/python265 --enable-shared
2: make
3: make install
4: edit /etc/ld.so.conf ( add /program2/python265/lib)
5:cd /program2/python265/lib; ldconfig
=== 修复bug===
(2.6.4,2.6.5中hashlib.py中有个bug:
Reference: https://dev.openwrt.org/browser/packages/lang/python/patches/120-force-internal-modules-for-hashlib.patch?rev=20372 )
### command ###
wget https://dev.openwrt.org/export/20372/packages/lang/python/patches/120-force-internal-modules-for-hashlib.patch --no-check-certificate
patch -Np1 -i 120-force-internal-modules-for-hashlib.patch setup.py
==================================================================================
包管理安装
(Reference: http://www.ibm.com/developerworks/cn/linux/l-cppeak3.html)
1: wget -q http://peak.telecommunity.com/dist/ez_setup.py
2: python ez_setup.py
在python-2.6/bin下,新增: easy_install,easy_install-2.6
setuptools 详细用法参考: http://peak.telecommunity.com/DevCenter/setuptools
Mysql数据库:
1: Download: http://sourceforge.net/projects/mysql-python/
2: tar xfz MySQL-python-1.2.1.tar.gz
cd MySQL-python-1.2.1
# edit site.cfg if necessary (修改成你mysql安装后,文件mysql_config的完整路径)
/program2/python265/bin/python setup.py build
/program2/python265/bin/python setup.py install
### Error #### 如果有这个错,请写python的全路径
/usr/bin/ld: cannot find -lpython2.6
############
APACHE mod_python
1: download
wget http://labs.renren.com/apache-mirror/httpd/modpython/mod_python-3.3.1.tgz
2: install (这里要求python编译时加上参数: --enable-shared)
./configure --with-apxs=/program1/apache-2.2.14/bin/apxs --with-python=/program2/python265/bin/python
make # (bug: https://issues.apache.org/jira/browse/MODPYTHON-249)
////////////////////////////////////////////////////////////////////////////////
另外的bug: https://bugzilla.redhat.com/show_bug.cgi?id=465246
错误如下:
&& touch connobject.slo
connobject.c: In function '_conn_read':
connobject.c:142: error: request for member 'next' in something not a structure or union
apxs:Error: Command failed with rc=65536
make[1]: *** [mod_python.so] Error 1
make[1]: Leaving directory `/program2/python265/install/mod_python-3.3.1/src'
make: *** [do_dso] Error 2
下载PATCH: https://bugzilla.redhat.com/attachment.cgi?id=319219
都安装好后,Apache 报错
1:ImportError: No module named _md5 (参考python安装后bug)
2: [Fri Aug 20 22:18:35 2010] [notice] child pid 21435 exit signal Segmentation fault (11)
Reference: http://www.dscpl.com.au/wiki/ModPython/Articles/ExpatCausingApacheCrash (不能修复)
/////////////////////////////////////////////////////////////////////////////
3: apache config
在httpd.conf加入 LoadModule python_module modules/mod_python.so
添加一个测试的实例的配置:
Alias /python "/program1/website/pythonweb"
<Directory /program1/website/pythonweb>
AllowOverride FileInfo
AddHandler mod_python .py
PythonHandler test
PythonDebug On
</Directory>
重启Apache
在/program1/website/pythonweb下新建一个文件test.py,内容如下:
from mod_python import apache
def handler(req):
req.write("Hello World!")
return apache.OK
打开浏览器,得到:
