运行马里奥游戏时此文件出现错误当我尝试运行文件 super_mario.py 时,我从以下链接( https://github.com/Ja1r0/DQN-play-SuperMario )下载了代码,我收到上述错误(pygame.error 视频系统未初始化)。
我在 windows10 中使用 ubuntu 18.04 小部件。
import platform
p_name = platform.system()
print(p_name)
import os
import pygame as pg
from . import tools
from . import constants as c
ORIGINAL_CAPTION = c.ORIGINAL_CAPTION
current_dir = os.path.dirname(os.path.realpath(__file__))
'''
os.environ['SDL_VIDEO_CENTERED'] = '1'
pg.init()
pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
pg.display.set_caption(c.ORIGINAL_CAPTION)
SCREEN = pg.display.set_mode(c.SCREEN_SIZE, 0, 32)
SCREEN_RECT = SCREEN.get_rect()
FONTS = tools.load_all_fonts(os.path.join("resources", "fonts"))
MUSIC = tools.load_all_music(os.path.join("resources", "music"))
GFX = tools.load_all_gfx(os.path.join("resources", "graphics"))
SFX = tools.load_all_sfx(os.path.join("resources", "sound"))
# dev env
'''
if True:#p_name == "aaa":
import os
import pygame as pg
from . import tools
from . import constants as c
ORIGINAL_CAPTION = c.ORIGINAL_CAPTION
os.environ['SDL_VIDEO_CENTERED'] = '1'
pg.init()
pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
pg.display.set_caption(c.ORIGINAL_CAPTION)
SCREEN = pg.display.set_mode(c.SCREEN_SIZE, 0, 32)
SCREEN_RECT = SCREEN.get_rect()
FONTS = tools.load_all_fonts(os.path.join("resources", "fonts"))
MUSIC = tools.load_all_music(os.path.join("resources", "music"))
GFX = tools.load_all_gfx(os.path.join("resources", "graphics"))
SFX = tools.load_all_sfx(os.path.join("resources", "sound"))
# aws
else:
import os
# import pygame as pg
from . import tools
from . import constants as c
ORIGINAL_CAPTION = c.ORIGINAL_CAPTION
os.environ['SDL_VIDEO_CENTERED'] = '1'
os.environ["SDL_VIDEODRIVER"] = "dummy"
os.environ["SDL_AUDIODRIVER"] = "dummy"
import pygame as pg
pg.init()
pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
pg.display.set_caption(c.ORIGINAL_CAPTION)
SCREEN = pg.display.set_mode(c.SCREEN_SIZE, 0, 32)
SCREEN_RECT = SCREEN.get_rect()
FONTS = tools.load_all_fonts(os.path.join(current_dir, "..", "resources", "fonts"))
MUSIC = tools.load_all_music(os.path.join(current_dir, "..", "resources", "music"))
GFX = tools.load_all_gfx(os.path.join(current_dir, "..", "resources", "graphics"))
SFX = tools.load_all_sfx(os.path.join(current_dir, "..", "resources", "sound"))
您说您在 windows10 中使用[the] ubuntu 18.04 小部件
(我猜您正在谈论适用于 Linux 的 Windows 子系统),它不带有视频显示器。它只是控制台,除非您安装了 X 服务器,例如xming。
错误视频系统未初始化
准确地告诉您:没有可以绘制可用窗口的视频系统。
因此,您可以尝试安装 X-server 或从 Windows 10 安装中运行代码,而不是 WSL。
我是一名优秀的程序员,十分优秀!