pygame2exe模块不是iterab

2024-09-30 03:25:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pygame站点(here)上的py2exe脚本编译一个只使用sys和pygame的简单程序。当我运行它时,我得到一个错误:

running py2exe
creating C:\Users\python2.6\Desktop\build
creating C:\Users\python2.6\Desktop\build\bdist.win32
creating C:\Users\python2.6\Desktop\build\bdist.win32\winexe
creating C:\Users\python2.6\Desktop\build\bdist.win32\winexe\collect-2.6
creating C:\Users\python2.6\Desktop\build\bdist.win32\winexe\bundle-2.6
creating C:\Users\python2.6\Desktop\build\bdist.win32\winexe\temp
creating C:\Users\python2.6\Desktop\dist
*** searching for required modules ***
Traceback (most recent call last):
  File "C:\Users\python2.6\Desktop\pyg2exe.py", line 170, in <module>
    BuildExe().run() #Run generation
  File "C:\Users\python2.6\Desktop\pyg2exe.py", line 161, in run
    dist_dir = self.dist_dir
  File "C:\Python26\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python26\lib\distutils\dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "C:\Python26\lib\distutils\dist.py", line 995, in run_command
    cmd_obj.run()
  File "C:\Python26\Lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python26\Lib\site-packages\py2exe\build_exe.py", line 296, in _run
    self.find_needed_modules(mf, required_files, required_modules)
  File "C:\Python26\Lib\site-packages\py2exe\build_exe.py", line 1306, in find_needed_modules
    mf.import_hook(f)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 719, in import_hook
    return Base.import_hook(self,name,caller,fromlist,level)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 136, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 181, in find_head_package
    if '.' in name:
TypeError: argument of type 'module' is not iterable

下面是pygame2exe代码:

^{pr2}$

我的密码是:

import pygame, sys
from pygame.locals import *

# set up pygame
pygame.init()

# set up the window
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption('Hello world!')

# set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

# set up fonts
basicFont = pygame.font.SysFont(None, 48)

# set up the text
text = basicFont.render('Hello world!', True, WHITE, BLUE)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery

# draw the white background onto the surface
windowSurface.fill(WHITE)

# draw a green polygon onto the surface
pygame.draw.polygon(windowSurface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))

# draw some blue lines onto the surface
pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120))
pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4)

# draw a blue circle onto the surface
pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)

# draw a red ellipse onto the surface
pygame.draw.ellipse(windowSurface, RED, (300, 250, 40, 80), 1)

# draw the text's background rectangle onto the surface
pygame.draw.rect(windowSurface, RED, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height + 40))

# get a pixel array of the surface
pixArray = pygame.PixelArray(windowSurface)
pixArray[480][380] = BLACK
del pixArray

# draw the text onto the surface
windowSurface.blit(text, textRect)

# draw the window onto the screen
pygame.display.update()

# run the game loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

我希望用这个来找出如何更好地使用pygame2exe,这样我就可以在一个更复杂的程序中使用它。在


Tags: theruninpybuildlinepygameusers

热门问题