简单Python实例,以及打包成.exe文件
2014-07-04 17:16
706 查看
1、工具准备:
我的Python版本是python 3.x的
打包工具:cxfreeze,我的是 windows 32bit的 http://sourceforge.net/projects/cx-freeze/files/4.3.2/
关联你的eclipse:
help->install new solftware->输入插件地址:http://download.aptana.com/studio3/plugin/install, 访问download.aptana.com/studio3会提示叫你把前面的地址输入到下面的work with 框中。
选中,然后一路next 下去。
安装成功之后, window->preferences->pyDev图片下面的最后一项,关联安装的python.exe
然后创建python的project呗:
写了一个简单的例子:
'''
Created on 2014-7-4
@author: liyao
'''
import os
oldWorld = None
newWorld = None
fileType = None
# scan the path you entered, then replace aim files
def scanDir(path, oldWorld, newWorld, fileType):
for root, dirs, files in os.walk(path):
for filespath in files:
if os.path.join(root, filespath).endswith("."+fileType):
replaceFun(os.path.join(root, filespath), oldWorld, newWorld)
# replace the old world as the new world
def replaceFun(filepath, oldWorld, newWorld):
lines = open(filepath, "r", encoding= "utf-8").readlines()
fp = open(filepath, "w")
for s in lines:
fp.write(s.replace(oldWorld, newWorld))
fp.close
flag = None
while 1:
print("==================================================")
print("====== 0、退出当前应用 =======")
print("====== 1、进入当前应用 =======")
print("====== =======")
print("==================================================")
flag = input("编号:")
if flag == "0":
print("谢谢使用")
break
elif flag == "1":
dir = input("enter your project,like:E:\python\Hellowin path=")
if not dir.strip():
print("is null dir")
exit(-1)
oldWorld = input("enter your old string =")
if not oldWorld.strip():
print("is null world")
exit(-1)
newWorld = input("enter your new string =")
if not newWorld.strip():
print("is null world")
exit(-1)
fileType = input("enter your file type,like:java,txt,xml type= ")
if not fileType.strip():
print("is null world")
exit(-1)
scanDir(dir, oldWorld, newWorld, fileType)
打包:
1、安装cxfreeze
2、C:\Python33\Scripts的目录下面会有的,安装它,会自动匹配到你的python安装文件路径下面。
把命令转到对应Scripts下面,才能执行cxfreeze的命令:
找到你的.py文件,通过命令:
如:cxfreeze C:\Python33\Scripts\Project.py --target-dir E:\然后会生成.exe等相关文件,这样打包就成功了:
参考:
http://huangda-hd.blog.163.com/blog/static/81808426201361741158158/
我的Python版本是python 3.x的
打包工具:cxfreeze,我的是 windows 32bit的 http://sourceforge.net/projects/cx-freeze/files/4.3.2/
关联你的eclipse:
help->install new solftware->输入插件地址:http://download.aptana.com/studio3/plugin/install, 访问download.aptana.com/studio3会提示叫你把前面的地址输入到下面的work with 框中。
选中,然后一路next 下去。
安装成功之后, window->preferences->pyDev图片下面的最后一项,关联安装的python.exe
然后创建python的project呗:
写了一个简单的例子:
'''
Created on 2014-7-4
@author: liyao
'''
import os
oldWorld = None
newWorld = None
fileType = None
# scan the path you entered, then replace aim files
def scanDir(path, oldWorld, newWorld, fileType):
for root, dirs, files in os.walk(path):
for filespath in files:
if os.path.join(root, filespath).endswith("."+fileType):
replaceFun(os.path.join(root, filespath), oldWorld, newWorld)
# replace the old world as the new world
def replaceFun(filepath, oldWorld, newWorld):
lines = open(filepath, "r", encoding= "utf-8").readlines()
fp = open(filepath, "w")
for s in lines:
fp.write(s.replace(oldWorld, newWorld))
fp.close
flag = None
while 1:
print("==================================================")
print("====== 0、退出当前应用 =======")
print("====== 1、进入当前应用 =======")
print("====== =======")
print("==================================================")
flag = input("编号:")
if flag == "0":
print("谢谢使用")
break
elif flag == "1":
dir = input("enter your project,like:E:\python\Hellowin path=")
if not dir.strip():
print("is null dir")
exit(-1)
oldWorld = input("enter your old string =")
if not oldWorld.strip():
print("is null world")
exit(-1)
newWorld = input("enter your new string =")
if not newWorld.strip():
print("is null world")
exit(-1)
fileType = input("enter your file type,like:java,txt,xml type= ")
if not fileType.strip():
print("is null world")
exit(-1)
scanDir(dir, oldWorld, newWorld, fileType)
打包:
1、安装cxfreeze
2、C:\Python33\Scripts的目录下面会有的,安装它,会自动匹配到你的python安装文件路径下面。
把命令转到对应Scripts下面,才能执行cxfreeze的命令:
找到你的.py文件,通过命令:
如:cxfreeze C:\Python33\Scripts\Project.py --target-dir E:\然后会生成.exe等相关文件,这样打包就成功了:
参考:
http://huangda-hd.blog.163.com/blog/static/81808426201361741158158/
相关文章推荐
- Python3实例:使用cx_Freeze打包成exe文件
- 在python中调用dll,并将dll以及python合并打包成一个exe文件的方法
- cxfreeze的安装问题 以及将打包Python3.4 成exe文件
- pyinstaller打包Python成为EXE文件,简易教程
- 用cx_Freeze把python打包成exe可执行文件
- ##计划任务## 把python文件打包成exe
- windows7下使用py2exe把python打包程序为exe文件
- python程序使用pyinstaller打包成单一.exe文件后,如何的到.exe文件所在目录?
- 手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件
- Python脚本打包为exe文件
- python中获取打包成执行文件(exe)和脚本运行文件的路径
- Tcl/tk实例—使用tclkit工具将脚本打包成可执行文件(.exe)
- Python脚本打包为exe文件 推荐
- 手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件
- 手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件
- 打包python程序为exe文件using cx_freeze
- 用cx_Freeze把python打包成exe可执行文件
- Python脚本打包为exe文件
- 手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件
- 利用PyInstaller把Python程序打包成exe可执行文件