大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索

[教学] 如何在ubuntu安装Python?部署一个hello world

[复制链接]
发表于 2015-6-19 23:58:42 | 显示全部楼层 |阅读模式
[教学] 如何在ubuntu安装Python?部署一个hello world

前提,你已经安装好了apache2

1. 安装libapache2-mod-python
  1. sudo apt-get install libapache2-mod-python
复制代码


2. 部署你的Directives
AddHandler mod_python py
PythonHandler mod_python.publisher
PythonDebug On
  1. DocumentRoot /var/www/domain.my
  2. ServerName domain.my
  3. ServerAlias www.domain.my
  4. <Directory "/var/www/domain.my">
  5. #allow from all
  6. #Options +ExecCGI
  7. AddHandler mod_python py
  8. PythonHandler mod_python.publisher
  9. PythonDebug On
  10. </Directory>
复制代码


3. Create一个file,命名test.py
  1. def index(req):
  2.   return "Hello World";
复制代码


4. www.domain.my/test.py 就成功啦,超简单的。


而外的httplib2 lib,如果你有需要
1. sudo apt-get install python3-httplib2
2. sudo apt-get install python-pip
3. sudo apt-get install python-pip3
4. pip2 install httplib2 --upgrade
5. pip3 install httplib2 --upgrade

常见问题
1. ^ IndentationError: unexpected indent
前面的空位少或多一个都不行,要一致的
def index(req):
        #Build query string & specify type of API call
        target = urlparse(uri + path )
        #return  target.geturl()
        method = 'GET'
        body = ''

2. .py was not found on this server.
我放这个就跑不了if __name__=="__main__":之后我就换成def index(req):

手机版|大马资讯论坛  

GMT+8, 2024-3-29 00:38 , Processed in 0.044818 second(s), 14 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表