使用 PyInstaller 将.py转换为.exe时如何修复"WARNING: Hidden import " pygame._view " not found!"?



这是我的代码的 MRE:

import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
screen.fill((255, 215, 0))
x_coordinate = 330
y_coordinate = 250
font = pygame.font.SysFont('comicsans', 30, False, False)
writing = font.render("this is a test", 1, (0,0,0))

running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
screen.blit(writing,(x_coordinate, y_coordinate))
pygame.display.update()
pygame.quit()

现在,当我使用 cmd 或 IDLE 运行它时,它可以完美运行。但是当我使用 pyinstaller 使其可执行文件(我使用的命令是"pyinstaller --onefile {python 文件名称}"(时,cmd 窗口上出现一条警告:"警告:找不到隐藏的导入"pygame._view"! 我认为pygame._view与pygame是不同的模块,所以我添加了import pygame._view无济于事(我也尝试使用pip安装它, 但不存在该名称的模块(。

现在,当我运行创建的可执行文件时,我收到一条错误消息,指出"测试.exe已停止工作"。

如何解决此问题?

将"comicsans"替换为"comicsansms"。出于某些原因,pygame。字体正在处理这种情况,即漫画不是系统字体,当作为py文件运行时但不在exe中

最新更新