py2exe使用遇到的问题

py2exe使用遇到的问题

我有个最简单的pygtk程序
想用py2exe包装一下
我用了下面的几个命令都不行
python setup.py py2exe
python setup.py py2exe -i gtk
python setup.py py2exe -p gtk
请问是不是缺少什么?

[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/python
#hello.py
import gtk

win=gtk.Window()
win.show()
gtk.main()


#!/usr/bin/python
# setup.py
from distutils.core import setup
import py2exe
setup(console=["hello.py"])

出现的错误是这样的

[Copy to clipboard] [ - ]
CODE:
*** copy extensions ***
copying D:\Python24\lib\site-packages\gtk-2.0\gtk\glade.pyd -> D:\1\dist
*** copy dlls ***
copying D:\Program Files\Common Files\GTK\2.0\bin\libxml2.dll -> D:\1\dist
copying D:\Program Files\Common Files\GTK\2.0\bin\libglade-2.0-0.dll -> D:\1\dis
t
copying D:\Python24\lib\site-packages\py2exe\run.exe -> D:\1\dist\hello.exe
The following modules appear to be missing
['gdk', 'ltihooks']

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.

   GDI32.dll - D:\WINNT\system32\GDI32.dll
   KERNEL32.dll - D:\WINNT\system32\KERNEL32.dll
   OLE32.dll - D:\WINNT\system32\OLE32.dll
   IMM32.DLL - D:\WINNT\system32\IMM32.DLL
   SHELL32.dll - D:\WINNT\system32\SHELL32.dll
   WS2_32.DLL - D:\WINNT\system32\WS2_32.DLL
   msvcrt.dll - D:\WINNT\system32\msvcrt.dll
   ADVAPI32.dll - D:\WINNT\system32\ADVAPI32.dll
   USER32.dll - D:\WINNT\system32\USER32.dll



[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/python
# setup.py
from distutils.core import setup
import py2exe
setup(windows=["hello.py"])

你的程序是GUI程序
还是不行
还是说找不到模块

[Copy to clipboard] [ - ]
CODE:
The following modules appear to be missing
['gdk', 'ltihooks']

楼主,你干什么把HELLO的程式和SETUP的程式放在一起啊,这需要两个文件啊..

用两个文件后,在DOS界面,路径选对,输入  setup.py  py2exe  就可以了..

不过这个py2exe不是有缺陷嘛,第三方软件的共同缺陷
是两个文件
一个hello.py是我的程序
一个setup.py
只是把他们贴在了一起

如果只包含简单的print语句
那么打包就没问题
但是如果用到了gtk的图形模块
打包的时候就说找不到那两个模块了
sigh
OK
问题已解决
在这个地方找到的答案
http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK
就是setup.py没写好
再补充一点
有时候用py2exe打包pygtk时pango包会出运行时错误
解决的办法是重新拷贝pango的那个DLL
我也是在google上找到的
大家可以看下面的原文

[Copy to clipboard] [ - ]
CODE:
I saw a very similar error message when using PyGtk & py2exe on
windows...perhaps it is something similar.

I was using py2exe to package up all the files needed to run my PyGtk
program, including DLLs.  It was copying the Pango DLL from my Gtk
installation but not some of the data files Pango needed (which were
installed along with Gtk in C:\GTK).  

When I ran my program, it found the copied DLL but wasn't able to find
the data files.  I found two ways to fix the problem:

1) copy the data files from C:\GTK and put them next to the Pango DLL.
In my case I had to copy C:\GTK\lib, C:\GTK\share, and one other
directory from C:\GTK which slips my mind at the moment

2) delete the copied pango DLL.  My program then used the one installed
in C:\GTK and was able to find the data files in C:\GTK

So, could your program be finding a 2nd copy of the pango DLL somewhere?

-Mark Ive