py2exe打包整个项目
这段时间做了用Python做了一个科学计算的项目,项目中用到了很多的第三方Python库,包括PyQt、traits、traitsui、matplotlib、pyface、table、numpy、tvtk等等。Python打包traits和traitsui很麻烦,选用了py2exe、bbfreeze等打包工具,最后在google的帮助下使用了py2exe解决了问题。
其主要难点是要知道你的项目中使用到的python库,然后在includes列表中添加这些Python库,以便能正确打包项目。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
import os
import glob
includes = []
includes.append("sip")
includes.append(numpy)
includes.append(numpy.core)
includes.append(pygments)
includes.append(pygments.*)
includes.append(pygments.filters)
includes.append(pygments.filters.*)
includes.append(pygments.formatters)
includes.append(pygments.formatters.*)
includes.append(pygments.lexers)
includes.append(pygments.lexers.*)
includes.append(pygments.styles)
includes.append(pygments.styles.*)
includes.append(scipy)
includes.append(xml)
includes.append(lxml)
includes.append(lxml.*)
includes.append(wx)
includes.append(wx.*)
includes.append(traits)
includes.append(traits.etsconfig.api.*)
includes.append(traits.etsconfig)
includes.append(traits.etsconfig.*)
includes.append(traitsui)
includes.append(traitsui.*)
includes.append(traitsui.qt4)
includes.append(traitsui.qt4.*)
includes.append(traitsui.qt4.extra)
includes.append(traitsui.qt4.extra.*)
includes.append(traitsui.editors)
includes.append(traitsui.editors.*)
includes.append(traitsui.extras)
includes.append(traitsui.extras.*)
includes.append(traitsui.menu)
includes.append(traitsui.menu.*)
includes.append(pyface)
includes.append(pyface.*)
includes.append(pyface.qt)
includes.append(pyface.qt.*)
includes.append(pyface.ui.qt4)
includes.append(pyface.ui.qt4.init)
includes.append(pyface.ui.qt4.*)
includes.append(pyface.ui.qt4.code_editor.*)
includes.append(pyface.ui.qt4.console.*)
includes.append(pyface.ui.qt4.tasks.*)
includes.append(pyface.ui.qt4.action.*)
includes.append(pyface.ui.qt4.timer.*)
includes.append(pyface.ui.qt4.wizard.*)
includes.append(pyface.ui.qt4.workbench.*)
includes.append(wx)
includes.append(wx.*)
includes.append(PyQt4)
includes.append(PyQt4.*)
includes.append(enable)
includes.append(enable.drawing)
includes.append(enable.tools)
includes.append(enable.wx)
includes.append(enable.wx.*)
includes.append(enable.qt4)
includes.append(enable.qt4.*)
includes.append(enable.savage)
includes.append(enable.savage.*)
includes.append(enable.savage.svg)
includes.append(enable.savage.svg.*)
includes.append(enable.savage.svg.backends)
includes.append(enable.savage.svg.backends.wx)
includes.append(enable.savage.svg.backends.wx.*)
includes.append(enable.savage.svg.css)
includes.append(enable.savage.compliance)
includes.append(enable.savage.trait_defs)
includes.append(enable.savage.trait_defs.*)
includes.append(enable.savage.trait_defs.ui)
includes.append(enable.savage.trait_defs.ui.*)
includes.append(enable.savage.trait_defs.ui.qt4)
includes.append(enable.savage.trait_defs.ui.qt4.*)
includes.append(tvtk)
includes.append(tvtk.*)
includes.append(tvtk.custom)
includes.append(tvtk.custom.*)
includes.append(tvtk.pipeline)
includes.append(tvtk.pipeline.*)
includes.append(tvtk.plugins)
includes.append(tvtk.plugins.*)
includes.append(tvtk.pyface)
includes.append(tvtk.pyface.*)
includes.append(tvtk.pyface.ui)
includes.append(tvtk.pyface.ui.*)
includes.append(tvtk.pyface.ui.qt4)
includes.append(tvtk.pyface.ui.qt4.*)
includes.append(tvtk.tools)
includes.append(tvtk.tools.*)
includes.append(tvtk.util)
includes.append(tvtk.util.*)
includes.append(tvtk.view)
includes.append(tvtk.view.*)
includes.append(matplotlib.backends)
includes.append(matplotlib.backends.backend_qt4agg)
includes.append(matplotlib.figure)
includes.append(tables)
includes.append(tables.*)
includes.append(apptools.preferences)
includes.append(apptools.preferences.*)
includes.append(apptools.preferences.ui)
includes.append(apptools.preferences.ui.*)
packages = []
data_folders = []
# Traited apps:
ETS_folder = rC:\Python27\Lib\site-packages
data_folders.append( ( os.path.join(ETS_folder,renable\images), renable\images) )
data_folders.append( ( os.path.join(ETS_folder,rtraitsui\qt4\images), rtraitsui\qt4\images) )
data_folders.append( ( os.path.join(ETS_folder,rtvtk\pyface\images\16x16), rtvtk\pyface\images\16x16) )
data_folders.append( ( os.path.join(ETS_folder,rpyface\images), rpyface\images) )
data_folders.append( ( os.path.join(ETS_folder,rpyface\ui\qt4\images), rpyface\ui\qt4\images) )
data_folders.append( ( os.path.join(ETS_folder,rpyface\ui\qt4\workbench\images), rpyface\ui\qt4\workbench\images) )
data_folders.append( ( os.path.join(ETS_folder,rtvtk), rtvtk) )
data_folders.append( ( os.path.join(ETS_folder,rtvtk\plugins\scene), rtvtk\plugins\scene) )
data_folders.append( ( os.path.join(ETS_folder,rmayavi\preferences), rmayavi\preferences) )
data_folders.append( ( os.path.join(ETS_folder,rmayavi\core\lut), rmayavi\core\lut) )
data_folders.append( ( os.path.join(ETS_folder,rmayavi\core\images), rmayavi\core\images) )
data_folders.append( ( os.path.join(ETS_folder,rmayavi\core\ui\images), rmayavi\core\ui\images) )
data_folders.append( ( os.path.join(ETS_folder,rtraitsui\image\library), rtraitsui\image\library) )
data_folders.append( ( os.path.join(ETS_folder,rPyQt4\plugins\imageformats), rimageformats))
data_folders.append( ( os.path.join(ETS_folder,rmatplotlib\mpl-data\images), r\matplotlib\mpl-data\images) )
rotor_resources_folder = C:\Users\cloud\workspace\Rotor3\src
data_folders.append( ( os.path.join(rotor_resources_folder,rresources), rresources) )
data_folders.append( ( os.path.join(rotor_resources_folder,rresources\file), rresources\file) )
data_folders.append( ( os.path.join(rotor_resources_folder,rresources\folder), rresources\folder) )
data_folders.append( ( os.path.join(rotor_resources_folder,rresources\toolbar), rresources\toolbar) )
data_folders.append( ( os.path.join(rotor_resources_folder,rresources\workspace), rresources\workspace) )
# Matplotlib
import matplotlib as mpl
data_files = mpl.get_py2exe_datafiles()
# Parsing folders and building the data_files table
for folder, relative_path in data_folders:
for file in os.listdir(folder):
f1 = os.path.join(folder,file)
if os.path.isfile(f1): # skip directories
f2 = relative_path, [f1]
data_files.append(f2)
setup(windows=[{"script":run2.py,"icon_resources":[(1,"xxx.ico")]}],
author="Hangzhou Dianzi University",
version = "1.0",
description = "DPT For Hangzhou Dianzi University",
name = "Hangzhou Dianzi University",
options = {"py2exe": { "optimize": 0,
"packages": packages,
"includes": includes,
"dll_excludes": ["MSVCP90.dll", "w9xpopen.exe"],
"dist_dir": dist,
"bundle_files":2,
"xref": False,
"skip_archive": True,
"ascii": False,
"custom_boot_script": ,
"compressed":False,
},},
data_files=data_files)
py2exe打包整个项目的更多相关文章
- PyQt4 py2exe 打包 HardwareManager
#!/usr/bin/env python # -*- coding: UTF-8 -*- # 1. 以下代码保存在HardwareManager项目的目录下,名称叫:setup.py: # 2. 打 ...
- py2exe 打包scipy时遇到的问题
最近写了个小程序,用PyQt5做的界面,写完之后用py2exe打包成独立的exe文件,运行正常. 后来由于需要,调用SciPy.io.loadmat,改写setup.py,打包之后运行错误,提示: T ...
- 打包java项目为可执行程序(exe)
一直都是编写了java程序后在控制台 javac --> java 命令运行,或者在eclipse中运行,今天突然想怎么可以写好了一个项目随处可以运行呢? 于是网上搜了步骤,跟着一步一步实现了, ...
- python+pygame游戏开发之使用Py2exe打包游戏
最近在用python+pygame 开发游戏,写完以后在分享给朋友玩的时候遇到了很大的问题,只有搭建了环境才能运行python脚本. 这会吓退99%以上的人……所以把我们的游戏打包(注意是打包而不是编 ...
- 使用py2exe打包你的py程序
软件环境:python3.3.4 + PyQt5 使用py2exe打包写好的py文件,过程如下: 在你要打包的代码文件(比如sample.py)的同文件夹建立一个python代码文件(比如setup. ...
- 项目androidAnt编译打包Android项目
时间紧张,先记一笔,后续优化与完善. Ant编译打包Android项目 在Eclipse中对Android项目停止编译和打包如果项目比较大的话会比较慢,所以改为Ant工具来停止编译和打包 Ant环境配 ...
- 使用bat批处理命令打包maven项目
使用批处理命令打包java项目,给我们发布war或jar包带来了很大的便利,附上代码,以作留存. ::huap-parent ::common-parent ::market-parent ::cus ...
- Android - Ant自动编译打包android项目 -- 1(转)
1. 背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...
- Angular企业级开发(6)-使用Gulp构建和打包前端项目
1.gulp介绍 基于流的前端自动化构建工具,利用gulp可以提高前端开发效率,特别是在前后端分离的项目中.使用gulp能完成以下任务: 压缩html.css和js 编译less或sass等 压缩图片 ...
随机推荐
- NOIP模拟赛 无线通讯网
[题目描述] 国防部计划用无线网络连接若干个边防哨所.2种不同的通讯技术用来搭建无线网络:每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫星电话线路的哨所(两边都 ...
- day3- python 注册
# .先把文件内容的账号密码放到list/字典 f = open('users') result = f.read() f.close() user_list = result.split() # u ...
- 记一次低级错误导致的mysql(111)
今天下午配好的双主多从服务器,两台主机+主机内安装好的6台虚拟机,两台Mysql master各授权好其slave的远程登录,原本好端端的能远程登录,晚上回来时候就发现其中一台master登录不上其s ...
- windows 2008r2+php5.6.28环境搭建详细过程
安装IIS7 安装php 网站验证 安装IIS7 1.打开服务器管理器(开始-计算机-右键-管理-也可以打开),添加角色 直接下一步 勾选Web服务器(IIS),下一步,有个注意事项继续下一步(这里我 ...
- 优酷项目之 ORM(数据库对象关系映射)代码重写
前言: 我们在操作数据库时候一般都是通过sql代码来操作mysql数据库中相关数据,这就需要懂得sql语句,那么怎么样才能在不懂sql语句的情况下通过我们所学的python代码来实现对mysql数据库 ...
- 嵌入式入门学习笔记3:[转]编译linux
摘自:https://blog.csdn.net/baidu_24256693/article/details/80115354 编译Linux是什么意思? Linux内核是Linux操作系统的核心, ...
- Linux入门学习笔记2:终端命令
LINUX操作系统学习 命令 附带建 cd .. 当前路径的上一层 ../.. 当前路径的上两层 . 当前路径 - 跳转到上一次所在路径 ...
- Applied Nonparametric Statistics-lec6
Ref: https://onlinecourses.science.psu.edu/stat464/print/book/export/html/8 前面都是对一两个样本的检查,现在考虑k个样本的情 ...
- poj2195 bfs+最小权匹配
题意:给个矩阵,矩阵里有一些人和房子(人数和房子数相等),一个人只进一个房子(可以路过房子而不进),每走一步花费1美金,求所有人都进入房子的最小花费,这是典型的二分图带权匹配问题. 这题就是建图有点麻 ...
- Python动态属性和特性(二)
内置的property经常用作装饰器,但它其实是一个类.在Python中,函数和类通常可以互换,因为二者都是可调用对象,而且没有实例化的new运算符,所以调用构造方法和调用工厂函数没有区别,只要能返回 ...