我正在尝试学习如何使用pygame,但是在运行它方面遇到了问题。我已按照https://www.pygame.org/wiki/GettingStarted这里的说明进行安装。
他们告诉您将其安装为
python3 -m pip install -U pygame --user
然后用
进行测试python3 -m pygame.examples.aliens
我在Ubuntu中运行了这些命令,并成功安装了pygame。但是,当我尝试运行示例时,我得到了
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
*我正在Microsoft商店的Linux的Windows子系统上使用Ubuntu终端。 https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6
**按照以下说明进行修复。 https://virtualizationreview.com/articles/2017/02/08/graphical-programs-on-windows-subsystem-on-linux.aspx
答案 0 :(得分:0)
要运行linux版本,您需要一个真正的linux系统,并带有一个X11服务器来显示窗口-我认为Windows子系统不支持。另一种选择是将python用于Windows,然后直接在Windows中安装pygame
答案 1 :(得分:-1)
您必须在开头添加“ pygame.init()”