Chinaunix

标题: pygtk做了个游戏,还没完成,迫不及待给大家看啦 :D [打印本页]

作者: bleem1998    时间: 2006-02-11 00:05
标题: pygtk做了个游戏,还没完成,迫不及待给大家看啦 :D
windows和linux都可以跑
但是没有用py2exe打包
因为打出来的包不能用
暂时不知道怎么解决
所以只有装了python的朋友可以运行了
直接运行./go.py揍可以啦
呵呵
多提建议呀兄弟们

更新了一下,增加了几个随机事件
谁能帮忙打个windows的单独执行包吗
感激了!!

[ 本帖最后由 bleem1998 于 2006-2-11 18:25 编辑 ]

zhfsj.zip

14.7 KB, 下载次数: 810

code


作者: wolfg    时间: 2006-02-11 13:51
windows安装pygtk有什么要求?
作者: bleem1998    时间: 2006-02-11 17:41
先装python
然后这个(gtk\glade)
http://prdownloads.sourceforge.n ... 10-rc1.exe?download
然后这个(pygtk)
http://ftp.gnome.org/pub/GNOME/s ... /pygtk-2.8.4.tar.gz
作者: wolfg    时间: 2006-02-12 23:49
原帖由 bleem1998 于 2006-2-11 17:41 发表
先装python
然后这个(gtk\glade)
http://prdownloads.sourceforge.n ... 10-rc1.exe?download
然后这个(pygtk)
http://ftp.gnome.org/pub/GNOME/sources/pygtk ...


多谢!我试了一下,windows下的安装:
先安装GTK runtime,可以用这个gladewin32
[url]http://gladewin32.sourceforge.net/


然后是pygtk的win32port
http://www.mapr.ucl.ac.be/~gustin/win32_ports/
为Python 2.4安装时一定要注意同时下载pycairo,就在pygtk下载链接的下面

呵呵,可以运行你的“珠海浮生记”了。

在windows下运行,有这样的message出现:
D:\Downloads\Python\pygtk\zhfsj\go.py:13: PangoWarning: Couldn't load font "瀹嬩
綋 9" falling back to "Sans 9"
  xml = gtk.glade.XML('zhfsj.glade')
System initialise...
D:\Downloads\Python\pygtk\zhfsj\go.py:22: PangoWarning: Couldn't load font "瀹嬩
綋 9" falling back to "Sans 9"
  gtk.main()
D:\Downloads\Python\pygtk\zhfsj\signal_handle.py:52: PangoWarning: Couldn't load
font "瀹嬩綋 9" falling back to "Sans 9"
  wd["win_msg"].show_all()

是字体的问题吧?

[ 本帖最后由 wolfg 于 2006-2-12 23:55 编辑 ]
作者: wolfg    时间: 2006-02-13 00:00
用py2exe生成exe文件后,错误信息是这样的。看来是找不到字体的问题。不影响程序的功能
D:\Downloads\Python\pygtk\zhfsj\dist\go.exe:13: PangoWarning: Couldn't load font "宋体 9" falling back to "Sans 9"
D:\Downloads\Python\pygtk\zhfsj\dist\go.exe:22: PangoWarning: Couldn't load font "宋体 9" falling back to "Sans 9"

[ 本帖最后由 wolfg 于 2006-2-13 00:05 编辑 ]
作者: wolfg    时间: 2006-02-13 00:04
原帖由 bleem1998 于 2006-2-11 00:05 发表
谁能帮忙打个windows的单独执行包吗


可以考虑结合py2exe和InnoSetup做一个windows下的安装程序

http://www.async.com.br/faq/pygt ... ;file=faq21.005.htp

有空的话,帮你看看
作者: bleem1998    时间: 2006-02-13 01:26
能否贴一下你的setup.py
我编译出来的总是出现libpango.dll的错误
作者: wolfg    时间: 2006-02-13 09:27
原帖由 bleem1998 于 2006-2-13 01:26 发表
能否贴一下你的setup.py
我编译出来的总是出现libpango.dll的错误

我用的就是你的setup.py啊
作者: jejwe    时间: 2006-02-13 14:51
原帖由 wolfg 于 2006-2-12 23:49 发表


多谢!我试了一下,windows下的安装:
先安装GTK runtime,可以用这个gladewin32
http://gladewin32.sourceforge.net/

然后是pygtk的win32port
[url]http://www.mapr ...

安装不成功啊,我把GTK runtime安装在C盘的GTK目录里,

gtk-2.0和cairo安装在
C:\Program Files\python\Lib\site-packages

一开始老是出现动态链接库的问题,说找不到,于是去GTK下BIN里的DLL文件复制到C:\WINNT\system32,但是这时又出现“无法定位程序输入点libconv_set_relocation_prefix于动态链接库ICONV.DLL上”
作者: wolfg    时间: 2006-02-13 15:09
你装的版本都是什么?
作者: jejwe    时间: 2006-02-13 15:15
PY2.4及上面提供的版本,
我干脆把BIN下的所有DLL库都COPY到system32下了,这下不提示了,不过出现其他问题
作者: jejwe    时间: 2006-02-13 15:24
D:\python\zhfsj>python go.py
go.py:13: PangoWarning: No builtin or dynamically loaded modules
were found. Pango will not work correctly. This probably means
there was an error in the creation of:
  'C:\WINNT\system32\etc\pango\pango.modules'
You may be able to recreate this file by running pango-querymodules.
  xml = gtk.glade.XML('zhfsj.glade')
go.py:13: PangoWarning: _pango_engine_shape_shape: assertion `PANGO_IS_FONT (fon
t)' failed
  xml = gtk.glade.XML('zhfsj.glade')

g.gif (13.22 KB, 下载次数: 91)

g.gif

作者: wolfg    时间: 2006-02-13 17:24
原帖由 jejwe 于 2006-2-13 15:24 发表
D:\python\zhfsj>python go.py
go.py:13: PangoWarning: No builtin or dynamically loaded modules
were found. Pango will not work correctly. This probably means
there was an error in the creation ...


我的安装过程是这样的:
1. gtk-win32-2.8.10-rc1.exe
http://gladewin32.sourceforge.net/

2. pycairo-1.0.2-1.win32-py2.4.exe
3. pygtk-2.8.4-1.win32-py2.4.exe
http://www.mapr.ucl.ac.be/~gustin/win32_ports/

[ 本帖最后由 wolfg 于 2006-2-13 17:29 编辑 ]
作者: bleem1998    时间: 2006-02-13 18:06
我打出来的包也出现和jejwe一样的错误
作者: wolfg    时间: 2006-02-13 20:13
原帖由 bleem1998 于 2006-2-13 18:06 发表
我打出来的包也出现和jejwe一样的错误

参考一下这个
http://www.async.com.br/faq/pygt ... ;file=faq21.002.htp

会不会是因为缺libglade?
作者: bleem1998    时间: 2006-02-13 22:45
估计不是
dist目录下有libglade-2.0-0.dll

搜索了一下错误信息
网上也有人遇到
解决办法是删除libpango-1.0-0.dll这个文件
程序就正常运行了
可是打包确实没有成功
拿到别的机器上用不了
作者: wolfg    时间: 2006-02-14 13:12
py2exe打包后的程序运行还是得需要GTK的runtime library
看这里
http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK
的最后一段

可以把GTK的runtime library用InnoSetup一起打包制成安装程序
作者: wolfg    时间: 2006-02-14 16:00
我修改过的setup.py

需要先安装InnoSetup
isetup-5.1.6.exe
http://www.jrsoftware.org/isdl.php
ChineseSimp-11-5.1.0.isl
http://www.jrsoftware.org/files/istrans/

最好也有安装python的ctypes模块
http://starship.python.net/crew/theller/ctypes/

假设GTK已经安装在C:\GTK
Gtk+/Win32 Runtime Environment Installer 2.8.10-rc1 (.exe, 5.21M)
http://gladewin32.sourceforge.net/modules/wfdownloads/visit.php?lid=97

  1. # setup.py
  2. # -*- coding: cp936 -*-
  3. # Author: wolfg

  4. # A setup script showing how to extend py2exe.
  5. #
  6. # In this case, the py2exe command is subclassed to create an installation
  7. # script for InnoSetup, which can be compiled with the InnoSetup compiler
  8. # to a single file windows installer.
  9. #
  10. # By default, the installer will be created as dist\Output\setup.exe.

  11. from distutils.core import setup
  12. import py2exe
  13. import sys
  14. import glob

  15. ################################################################
  16. # arguments for the setup() call

  17. livinginzhuhai = dict(
  18.     script = "go.py",
  19.     #other_resources = [],
  20.     #icon_resources = [(1, "check.ico")],
  21.     dest_base = r"bin\go")

  22. zipfile = r"lib\shardlib"

  23. options = {"py2exe":
  24.             {
  25.               "compressed": 1,
  26.               "optimize": 2,
  27.               "packages": "encodings",
  28.               "includes": "cairo, pango, pangocairo, atk, gobject",            
  29.             }
  30.           }

  31. ################################################################
  32. import os

  33. GTKDIR = 'C:\\gtk\\'
  34. os.environ['PATH'] += ";%s/lib;%s/bin" % (GTKDIR, GTKDIR)

  35. GTK_RUNTIME_FILES = glob.glob(GTKDIR + 'etc\\*\\*')

  36. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\*.a')
  37. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\*.alias')
  38. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\*.lib')
  39. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\glib-2.0\\include\\*.*')
  40. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\gtk-2.0\\2.4.0\\*\\*.*')
  41. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\gtk-2.0\\include\\*.*')
  42. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\gtkglext-1.0\\include\\*.*')
  43. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\libglade\\2.0\\include\\*.*')
  44. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\pango\\1.4.0\\modules\\*.*')
  45. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\pkgconfig\\*.*')

  46. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\aclocal\\*')
  47. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\xml\\libglade\\*')
  48. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\pixmaps\\*.png')
  49. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\pixmaps\\glade-2\\*.png')
  50. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\locale\\zh_CN\\*\\*')
  51. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\themes\\Default\\*\\*')
  52. GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\themes\\MS-Windows\\*\\*')

  53. class InnoScript:
  54.     def __init__(self,
  55.                  name,
  56.                  install_dir,
  57.                  lib_dir,
  58.                  dist_dir,
  59.                  windows_exe_files = [],
  60.                  lib_files = [],
  61.                  version = "1.0",
  62.                  output_basename = "Setup"):
  63.         self.lib_dir = lib_dir
  64.         self.dist_dir = dist_dir
  65.         if not self.dist_dir[-1] in "\\/":
  66.             self.dist_dir += "\\"
  67.         self.name = name
  68.         self.install_dir = install_dir
  69.         self.version = version
  70.         self.output_basename = output_basename
  71.         self.windows_exe_files = [self.chop(p) for p in windows_exe_files]
  72.         self.lib_files = [self.chop(p) for p in lib_files]
  73.         

  74.     def chop(self, pathname):
  75.         assert pathname.startswith(self.dist_dir)
  76.         return pathname[len(self.dist_dir):]
  77.    
  78.     def create(self, pathname="dist\\livinginzhuhai.iss"):
  79.         self.pathname = pathname
  80.         ofi = self.file = open(pathname, "w")
  81.         print >> ofi, "; WARNING: This script has been created by py2exe. Changes to this script"
  82.         print >> ofi, "; will be overwritten the next time py2exe is run!"
  83.         print >> ofi, r"[Setup]"
  84.         print >> ofi, r"AppName=%s" % self.name
  85.         print >> ofi, r"AppVerName=%s %s" % (self.name, self.version)
  86.         print >> ofi, r"DefaultDirName={pf}\%s" % self.install_dir
  87.         print >> ofi, r"DefaultGroupName=%s" % self.name
  88.         print >> ofi, r"Compression=lzma"
  89.         print >> ofi, r"SolidCompression=yes"
  90.         print >> ofi, r"OutputBaseFilename=%s" % self.output_basename
  91.         print >> ofi

  92.         print >> ofi, r"[Files]"
  93.         for path in self.windows_exe_files + self.lib_files:
  94.             print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' % (path, os.path.dirname(path))        
  95.         
  96.         for src, dest in [(p, p[len(GTKDIR):]) for p in GTK_RUNTIME_FILES]:
  97.           print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' % (src, os.path.dirname(dest))
  98.         print >> ofi
  99.         
  100.         print >> ofi, r"[Tasks]"
  101.         print >> ofi, r'Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked'
  102.         print >> ofi
  103.         
  104.         print >> ofi, r"[Icons]"
  105.         for path in self.windows_exe_files:
  106.             print >> ofi, r'Name: "{group}\%s"; Filename: "{app}\%s"; WorkingDir: "{app}\%s"' % \
  107.                   (self.name, path, os.path.dirname(path))
  108.         print >> ofi, r'Name: "{group}\Uninstall %s"; Filename: "{uninstallexe}"' % self.name        
  109.         print >> ofi, r'Name: "{userdesktop}\%s"; Filename: "{app}\bin\go.exe"; Tasks: desktopicon; WorkingDir: "{app}\bin"' % self.name
  110.         print >> ofi
  111.         
  112.         print >> ofi, r"[Run]"
  113.         print >> ofi, r'Filename: "{app}\bin\go.exe"; Description: "%s"; Flags: postinstall shellexec skipifsilent' % (u'开始“珠海浮生记”').encode('cp936')
  114.         print >> ofi
  115.         
  116.         print >> ofi, r"[Languages]"
  117.         print >> ofi, r'Name: "cn"; MessagesFile: "C:\Program Files\Inno Setup 5\Languages\ChineseSimp.isl"'
  118.         print >> ofi
  119.         
  120.     def compile(self):
  121.         try:
  122.             import ctypes
  123.         except ImportError:
  124.             try:
  125.                 import win32api
  126.             except ImportError:
  127.                 import os
  128.                 os.startfile(self.pathname)
  129.             else:
  130.                 print "Ok, using win32api."
  131.                 win32api.ShellExecute(0, "compile",
  132.                                                 self.pathname,
  133.                                                 None,
  134.                                                 None,
  135.                                                 0)
  136.         else:
  137.             print "Cool, you have ctypes installed."
  138.             res = ctypes.windll.shell32.ShellExecuteA(0, "compile",
  139.                                                       self.pathname,
  140.                                                       None,
  141.                                                       None,
  142.                                                       0)
  143.             if res < 32:
  144.                 raise RuntimeError, "ShellExecute failed, error %d" % res


  145. ################################################################

  146. from py2exe.build_exe import py2exe

  147. class build_installer(py2exe):
  148.     # This class first builds the exe file(s), then creates a Windows installer.
  149.     # You need InnoSetup for it.
  150.     def run(self):
  151.         # First, let py2exe do it's work.
  152.         py2exe.run(self)

  153.         lib_dir = self.lib_dir
  154.         dist_dir = self.dist_dir
  155.         
  156.         # create the Installer, using the files py2exe has created.
  157.         script = InnoScript(u"珠海浮生记".encode('cp936'),
  158.                             u"珠海浮生记".encode('cp936'),
  159.                             lib_dir,
  160.                             dist_dir,
  161.                             self.windows_exe_files,
  162.                             self.lib_files,
  163.                             '1.0',
  164.                             output_basename="Setup"
  165.                             )
  166.         print "*** creating the inno setup script***"
  167.         script.create()
  168.         print "*** compiling the inno setup script***"
  169.         script.compile()
  170.         # Note: By default the final setup.exe will be in an Output subdirectory.

  171. ################################################################

  172. setup(
  173.     options = options,
  174.     # The lib directory contains everything except the executables and the python dll.
  175.     zipfile = zipfile,
  176.     windows = [livinginzhuhai],
  177.     # use out build_installer class as extended py2exe build command
  178.     cmdclass = {"py2exe": build_installer},
  179.     data_files=[("bin", ["zhfsj.glade", ])]
  180.     )
复制代码

[ 本帖最后由 wolfg 于 2006-2-14 16:05 编辑 ]
作者: bleem1998    时间: 2006-02-14 19:19
出现这个错误

  1. D:\zhfsj>python setup.py py2exe
  2. running py2exe
  3. *** searching for required modules ***
  4. Traceback (most recent call last):
  5.   File "setup.py", line 199, in ?
  6.     data_files=[("bin", ["zhfsj.glade", ])]
  7.   File "D:\Python24\lib\distutils\core.py", line 149, in setup
  8.     dist.run_commands()
  9.   File "D:\Python24\lib\distutils\dist.py", line 946, in run_commands
  10.     self.run_command(cmd)
  11.   File "D:\Python24\lib\distutils\dist.py", line 966, in run_command
  12.     cmd_obj.run()
  13.   File "setup.py", line 169, in run
  14.     py2exe.run(self)
  15.   File "D:\Python24\Lib\site-packages\py2exe\build_exe.py", line 197, in run
  16.     self._run()
  17.   File "D:\Python24\Lib\site-packages\py2exe\build_exe.py", line 248, in _run
  18.     self.find_needed_modules(mf, required_files, required_modules)
  19.   File "D:\Python24\Lib\site-packages\py2exe\build_exe.py", line 1144, in find_
  20. eeded_modules
  21.     mf.import_hook(mod)
  22.   File "D:\Python24\Lib\site-packages\py2exe\mf.py", line 103, in import_hook
  23.     return Base.import_hook(self,name,caller,fromlist)
  24.   File "D:\Python24\lib\modulefinder.py", line 124, in import_hook
  25.     q, tail = self.find_head_package(parent, name)
  26.   File "D:\Python24\lib\modulefinder.py", line 178, in find_head_package
  27.     raise ImportError, "No module named " + qname
  28. ImportError: No module named pangocairo
  29. D:\zhfsj>
复制代码

作者: wolfg    时间: 2006-02-15 09:30
ImportError: No module named pangocairo
你有安装pycairo模块吗?
http://www.mapr.ucl.ac.be/~gusti ... 2-1.win32-py2.4.exe
作者: bleem1998    时间: 2006-02-15 19:43
果然是没有安装pycairo
可是安装后打包依然不行
运行时错误是一样的。。。。

不过InnoSetup这个东西着实不错!!


[ 本帖最后由 bleem1998 于 2006-2-15 19:54 编辑 ]
作者: wolfg    时间: 2006-02-16 09:18
原帖由 bleem1998 于 2006-2-15 19:43 发表
果然是没有安装pycairo
可是安装后打包依然不行
运行时错误是一样的。。。。

不过InnoSetup这个东西着实不错!!


呵呵,我用InnoSetup很久了。

我上面的那个脚本中创建的InnoSetup工程里已经包含GTK的runtime了,我这里试了,安装在没有GTK的机器上是没有问题的。
作者: Groot    时间: 2006-02-16 11:07
唉.......我下不了啊.
作者: yuki-angel    时间: 2006-03-01 14:29
打包不能用么?
作者: bleem1998    时间: 2006-03-01 18:02
我在windows下打的包不能用
不太会用py2exe

作者: wolfg    时间: 2006-03-02 09:28
原帖由 bleem1998 于 2006-3-1 18:02 发表
我在windows下打的包不能用
不太会用py2exe


我写的setup.py也不行吗?
作者: bleem1998    时间: 2006-03-02 16:19
8行
一样的错误
我想可能是我们用的GTK不一样吧
作者: 镜花缘    时间: 2006-03-26 22:28
不是很明白.建议写详细一点.
作者: pcbfans    时间: 2011-10-19 09:01
这个游戏好久没有更新了吧?好期待哦
作者: aixcradent    时间: 2011-10-19 09:11
python写程序有前途吗?
作者: gamerjzy    时间: 2012-04-03 16:22
回复 7# bleem1998

py2exe有問題的話,那你有沒有試過Pyinstaller ?
作者: hansion3406    时间: 2012-09-09 01:17
佩服你,能发这么好的帖子,厉害
作者: CanuxCheng    时间: 2015-06-04 13:04
为什么你的安装包不能一并把python和pygtk都给装了???
作者: 1091003979    时间: 2015-12-25 09:35
学了多久了。。
作者: substr函数    时间: 2016-01-03 16:08
下不了啊[]
好期待哦[]




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2