这段时间做了用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. STL容器之Array[转]

    转自https://blog.csdn.net/sin_geek/article/details/51067874 作者 Sin_Geek 简介 array在头文件<array> 中定义 ...

  2. NOIp2017囤题计划

    马上就要NOIp2017了,应该囤些题目吧…… 好的这只是一个开始 upd - 11.5 1.p1576 最小花费 无向图,dijisktra 2.p1339 [USACO09OCT]热浪Heat W ...

  3. linux优化之优化开机自启动服务

    过滤出来需要的开机自启动项:chkconfig  --list|grep  3:on|grep  -v  "crond|sshd|network|rsyslog|sysstat" ...

  4. mysql 的 case when 用法

    正确的格式: case when condition then result when condition then result when condition then result else re ...

  5. Go IO && bufio

    IO IO包 是对数据流的操作.从哪里来, 怎么处理,再到哪里去. 图片来源 https://medium.com/learning-the-go-programming-language/strea ...

  6. 汇编语言 Part 1——简介、基本语法、内存分段与内存地址

    简介 什么是汇编语言? 汇编语言是一种低级的编程语言,在程序的语句和体系结构的机器代码指令之间有很强的对应关系. 每种汇编语言都特定于特定的计算机体系结构,但需要解释或编译.汇编语言也可以称为符号机器 ...

  7. ubuntu gcc的下载链接,比较快的。

    http://mirrors.163.com/ubuntu-releases/ http://xhmikosr.1f0.de/tools/msys/

  8. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A.Saving Tang Monk II(优先队列广搜)

    #include<bits/stdc++.h> using namespace std; ; ; char G[maxN][maxN]; ]; int n, m, sx, sy, ex, ...

  9. HDU 4729 An Easy Problem for Elfness 主席树

    题意: 给出一棵树,每条边有一个容量. 有若干次询问:\(S \, T \, K \, A \, B\),求路径\(S \to T\)的最大流量. 有两种方法可以增大流量: 花费\(A\)可以新修一条 ...

  10. 【ajax】全面总结

    Ajax 的全面总结 2017-11-03 山外de楼 JavaScript Ajax在前端开发中有着举足轻重的地位,关于Ajax的使用和注意事项一直是一个重要的话题,借此机会,本文希望对Ajax做一 ...