Reference:

  1. Slithy docs — packaging presentations with py2exe - Isotropic.org


如果想用py2exe去包含有Pmw的程式,必須照下面四個步驟,不然會有問題

Traceback (most recent call last):
  File "main_button_page.py", line 20, in <module>
  File "Pmw\__init__.pyc", line 28, in <module>
WindowsError: [Error 3] 系統找不到指定的路徑。: 'C:\\Project\\Air_pollution\\GUI\\dist\\library.zip\\Pmw/*.*'

Solution:

Make a static version of Pmw.

Slithy uses a package called Pmw which normally dynamically loads pieces of itself as needed. This doesn't work with py2exe, so we need to fix it. You'll only need to do this once for your presentation; if you make a change to your script and repackage you can skip this step.

  1. cd to c:\python22\lib\site-packages\Pmw\Pmw_1_1\bin. (Assuming python is installed in the default c:\python22; change the paths if you installed Python somewhere else.
  2. run "python bundlepmw.py c:\python22\lib\site-packages\Pmw\Pmw_1_1\lib". This will create a file called "Pmw.py" in the current directory.
  3. copy "Pmw.py" to your main script directory.
  4. copy "..\lib\PmwBlt.py" and "..\lib\PmwColor.py" to your main script directory, too. (也就是放到要跑setup.py目錄下)

setup.py:

from distutils.core import setup
import py2exe
import glob

opts = {
    'py2exe': { "includes" : ["matplotlib.backends",  "matplotlib.backends.backend_qt4agg",
                               "matplotlib.figure","pylab", "numpy",
                               "matplotlib.backends.backend_tkagg"],
                'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg',
                             '_fltkagg', '_gtk', '_gtkcairo', ],
                'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                'libgobject-2.0-0.dll']
              }
       }

data_files= [(r'mpl-data',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*')),
(r'mpl-data',[r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
(r'mpl-data\images',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\images\*.*')),
(r'mpl-data\stylelib',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\stylelib\*.*')),
(r'mpl-data\fonts',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts\*.*'))]


setup(
    windows = ['main_button_page.py'], options=opts, data_files=data_files
)

results matching ""

    No results matching ""