标签:
这段时间做了用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)
标签:
原文地址:http://www.cnblogs.com/jefree/p/4461992.html