Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "WARNING: Hidden import "pygame._view" not found!" when converting .py to .exe using PyInstaller?

This is the MRE of my code:

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()

Now, when I run this using cmd or IDLE, it runs perfectly. But when I make its executable (the command I used was "pyinstaller --onefile {name of python file}") using pyinstaller, there appears a warning on the cmd window: "WARNING: Hidden import "pygame._view" not found!" I thought that pygame._view is a different module than pygame, so I added import pygame._view to no avail (I also tried to install it using pip, but no module exists by that name).

Now, when I run the executable created, I get an error message which says, "test.exe has stopped working".

How do I fix this problem?

like image 466
tryingtobeastoic Avatar asked Jul 03 '20 14:07

tryingtobeastoic


1 Answers

Replace "comicsans" with "comicsansms". For some reasons pygame.Fonts is handling the situation, ie comicsans not being a System Font, when run as a py file but not within the exe

like image 199
Eric Mathieu Avatar answered Nov 03 '22 22:11

Eric Mathieu