【发布时间】:2019-11-24 14:27:03
【问题描述】:
将我的 .py 程序转换为 .exe 后,我的程序停止运行。我得到WARNING: Hidden import information pygame._view "not found!"。我尝试导入该模块,但该模块不存在。我在互联网上搜索了解决方案,但没有发现任何有用的东西。很多回复说这个问题在较新的pygame版本中是不存在的,其余的回答也没有用。但这是最新版本。有关 Pygame 和 Pyinstaller 以及我的代码的更多信息:https://repl.it/@Kadinus/MyGame !!!
在这个站点上,我的 .exe 程序可以运行,但如果我直接在我的 PC 上启动它,它就无法运行。
Pygame 版本:1.9.6
Pyinstall 版本:3.5
import pygame
print ('Stage 1')
class Person():
def __init__(self):
self.x = 275
self.Y = 275
self.square = pygame.Rect(275, 275, 25, 25)
self.font = pygame.font.Font(None, 40)
#'self.massage = None' is written for example.
self.massage = None
def draw (self):
pygame.draw.rect(window, (0, 0, 0), self.square, 3)
text = self.font.render('Hi', 300, (0, 0, 0), (255, 200, 200))
textpos = text.get_rect(x=10, y=10)
window.blit(text, textpos)
pygame.init()
#Create the window and set its size.
window = pygame.display.set_mode (( 600, 600 ))
window.fill((255, 255, 255))
exit = False
print ('Stage 2')
#--------The problem is here--------
person = Person()
#-----------------------------------
print ('Stage 3')
while exit == False :
pygame.time.delay(5)
person.draw()
#Check if the user closes the window.
for event in pygame.event.get() :
if event.type == pygame.QUIT :
exit = True
pygame.display.update()
print ('Stage 4')
我希望代码运行到最后没有错误。
【问题讨论】:
-
代码中突出显示问题
-
repl.it真的编译并执行 .exe 文件,还是只是在 python 解释器中运行你的main.py文件?MyGame_Test.exe是如何创建的?
标签: python pygame pyinstaller