这段时间做了用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打包整个项目的更多相关文章

  1. PyQt4 py2exe 打包 HardwareManager

    #!/usr/bin/env python # -*- coding: UTF-8 -*- # 1. 以下代码保存在HardwareManager项目的目录下,名称叫:setup.py: # 2. 打 ...

  2. py2exe 打包scipy时遇到的问题

    最近写了个小程序,用PyQt5做的界面,写完之后用py2exe打包成独立的exe文件,运行正常. 后来由于需要,调用SciPy.io.loadmat,改写setup.py,打包之后运行错误,提示: T ...

  3. 打包java项目为可执行程序(exe)

    一直都是编写了java程序后在控制台 javac --> java 命令运行,或者在eclipse中运行,今天突然想怎么可以写好了一个项目随处可以运行呢? 于是网上搜了步骤,跟着一步一步实现了, ...

  4. python+pygame游戏开发之使用Py2exe打包游戏

    最近在用python+pygame 开发游戏,写完以后在分享给朋友玩的时候遇到了很大的问题,只有搭建了环境才能运行python脚本. 这会吓退99%以上的人……所以把我们的游戏打包(注意是打包而不是编 ...

  5. 使用py2exe打包你的py程序

    软件环境:python3.3.4 + PyQt5 使用py2exe打包写好的py文件,过程如下: 在你要打包的代码文件(比如sample.py)的同文件夹建立一个python代码文件(比如setup. ...

  6. 项目androidAnt编译打包Android项目

    时间紧张,先记一笔,后续优化与完善. Ant编译打包Android项目 在Eclipse中对Android项目停止编译和打包如果项目比较大的话会比较慢,所以改为Ant工具来停止编译和打包 Ant环境配 ...

  7. 使用bat批处理命令打包maven项目

    使用批处理命令打包java项目,给我们发布war或jar包带来了很大的便利,附上代码,以作留存. ::huap-parent ::common-parent ::market-parent ::cus ...

  8. Android - Ant自动编译打包android项目 -- 1(转)

    1.  背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...

  9. Angular企业级开发(6)-使用Gulp构建和打包前端项目

    1.gulp介绍 基于流的前端自动化构建工具,利用gulp可以提高前端开发效率,特别是在前后端分离的项目中.使用gulp能完成以下任务: 压缩html.css和js 编译less或sass等 压缩图片 ...

随机推荐

  1. Mutations-freecodecamp算法题目

    Mutations(比较字符串) 要求 如果数组第一个字符串元素包含了第二个字符串元素的所有字符,函数返回true. 不用考虑大小写和字符顺序 思路 将数组中的两个字符串小写化 将第二个数组元素(第二 ...

  2. mysql命令行复制数据库

    为了方便快速复制一个数据库,可以用以下命令将db1数据库的数据以及表结构复制到newdb数据库创建新的数据库#mysql -u root -p123456 mysql>CREATE DATABA ...

  3. Python数据分析【炼数成金15周完整课程】

    点击了解更多Python课程>>> Python数据分析[炼数成金15周完整课程] 课程简介: Python是一种面向对象.直译式计算机程序设计语言.也是一种功能强大而完善的通用型语 ...

  4. 【Windows7注册码】

    [文章转载自 http://www.win7zhijia.cn/jiaocheng/win7_19324.html] 一.神Key: KH2J9-PC326-T44D4-39H6V-TVPBY TFP ...

  5. STM8时基单元

    STM8时基单元 时基单元包含: 16位向上/向下计数器 16位自动重载寄存器 重复计数器 预分频器 (图29:STM8 时基单元) 16位计数器,预分频器,自动重载寄存器和重复计数器寄存器都可以通过 ...

  6. loj2030 「SDOI2016」储能表

    ref ref 一个点就是一个数对 \((x,y)\). 记状态 \(f[i][1/0][1/0][1/0]\) 和 \(g[i][1/0][1/0][1/0]\),其中三个 \(1/0\) 取值分别 ...

  7. Selenium WebDriver-操作下拉框内容

    操作下拉框中的内容 #encoding=utf-8 import unittest import time import chardet from selenium import webdriver ...

  8. dict的特性和基本语法——python3.6

    特性 key:value结构,字典中的每一个元素,都是键值对 key必须可被hash,且必须为不可变数据类型,必须唯一 可存放任意多个值,可修改,可以不唯一 无序 查找速度快,因为hash可以把key ...

  9. pytion3--class一个更实际的例子

    class一个更实际的例子 到目前为止,我们所看的大多数例子都是人为创造而且是独立完备的,其目的是为了帮助你把注意力集中在基础知识上.然而,本章的结尾是一个较大的例子,把我们所学的大多数概念都聚合在这 ...

  10. Educational Codeforces Round 38 (Rated for Div. 2)

    这场打了小号 A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input sta ...