读书人

施用Python编写免安装运行时、以Windo

发布时间: 2013-04-09 16:45:09 作者: rapoo

使用Python编写免安装运行时、以Windows后台服务形式运行的WEB服务器
构建环境安装python2.7安装Setup Tools

在https://pypi.python.org/pypi/setuptools获取安装脚本的链接http://peak.telecommunity.com/dist/ez_setup.py,下载并运行

使用Setup Tools自动下载安装webpy库

运行"C:\Python27\Scripts>easy_install.exe web.py"

手动下载安装pywin32库

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

下载并安装py2exe(也可使用PyInstaller、cxfreeze打包python程序)



编写脚本WebServer.py

# mysetup.pyfrom distutils.core import setupimport py2exesetup(service=["WindowsService"])



打包成独立可执行文件

python setup.py py2exe



安装为windows服务并运行

sc create MyPythonServer binPath= f:\desktop\dist\WindowsService.exe

sc start MyPythonServer

在浏览器中访问:”http://127.0.0.1:8089/visit/whatever“,结果显示"you are visiting /visit/whatever"



下载



参考

python访问REST

用Python实现CRUD功能REST服务

Getting RESTful with web.py

Web.py初探:安装与HelloWorld

使用py2exe制作免运行时的可执行文件

Web.py初探:安装与HelloWorld

Create win32 services using Python and py2exe


Python在windows下打包exe程序

读书人网 >Web前端

热点推荐