简体   繁体   中英

pygame.error: video system not initialized when trying to run examples

I'm trying to learn how to use pygame, but I'm having issues with running it. I installed it with the instructions here https://www.pygame.org/wiki/GettingStarted .

They tell you to install it with

python3 -m pip install -U pygame --user

and then to test it with

python3 -m pygame.examples.aliens

I ran these commands in Ubuntu and pygame was successfully installed. However, when I try to run the example I get

ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4771:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
Warning, no sound
Traceback (most recent call last):
 File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
 File "/home/Paul/.local/lib/python3.5/site-packages/pygame/examples/aliens.py", line 321, in <module>
    if __name__ == '__main__': main()
 File "/home/Paul/.local/lib/python3.5/site-packages/pygame/examples/aliens.py", line 188, in main
     bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32)
pygame.error: video system not initialized

*I'm using Ubuntu terminal on Windows subsystem for Linux from the microsoft store. https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6

**Following these instructions fixed it. https://virtualizationreview.com/articles/2017/02/08/graphical-programs-on-windows-subsystem-on-linux.aspx

To run the linux version you need a real linux system, with a X11 server to display the window - I don't think that works with the windows subsystem. Another option is to use python for windows and install pygame in windows directly

您必须在开头添加“ pygame.init()”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM