pygame项目无法运行: "pygame.error: 没有可用的视频设备"

3

更新1:我已经卸载、重新安装并按照Pygame网站上的说明安装依赖项/构建Pygame。结果发现我缺少依赖项,因为当我尝试运行setup.py脚本时,Python会提示。

SDL     : found 1.2.15
FONT    : not found
IMAGE   : not found
MIXER   : not found
SMPEG   : found 0.4.5
PNG     : not found
JPEG    : not found
SCRAP   : not found
PORTMIDI: found
PORTTIME: found

我在其他地方有一个对应缺失包的列表。我的问题是:我需要修改哪个环境变量才能使这些包被检测到?(在这样做时,我需要提供什么?每个文件所需的共享对象吗?)

注:系统详细信息- Linux Mint 17.2 Cinnamon 64位。 Cinnamon 版本:2.6.13。 显卡: Intel Corporation Broadwell-U 集成显卡。 7.7 GiB 内存, i5 处理器。

我正在尝试在我的新设备上运行pygame以制作一些游戏。我安装了libSDL和最近的pygame;在尝试运行其他人制作的三个不同游戏后,我遇到了同样的错误:
>~/Downloads/bubble $ python run.py
Traceback (most recent call last):
File "run.py", line 2, in <module>
   from classes.game import *
File "/home/---/Downloads/bubble/classes/game.py", line 2, in <module>
   from .arrow import *
File "/home/---/Downloads/bubble/classes/arrow.py", line 1, in <module>
   from .constantes import *
File "/home/---/Downloads/bubble/classes/constantes.py", line 35, in <module>
scr = display.set_mode(screen.size)
pygame.error: No available video device

我为了查看问题/尝试解决它所做的事情:

1)仔细检查我是否安装了libSDL及其相应的开发包。[经过研究,发现这种错误的一个原因是没有安装libSDL]

>~aptitude search sdl | grep -F 'i '

i A libalien-sdl-perl               - helper to get, build and use SDL libraries
i A libsdl-console                  - Console that can be added to any SDL appli
i   libsdl-console-dev              - Console that can be added to any SDL appli
i A libsdl-gfx1.2-4                 - drawing and graphical effects extension fo
i   libsdl-gst                      - SDL bindings for GNU Smalltalk            
i   libsdl-image-gst                - SDL_image bindings for GNU Smalltalk      
i   libsdl-image1.2                 - Image loading library for Simple DirectMed
i   libsdl-image1.2:i386            - Image loading library for Simple DirectMed
i A libsdl-image1.2-dev             - Image loading library for Simple DirectMed
i   libsdl-mixer-gst                - SDL_mixer bindings for GNU Smalltalk      
i A libsdl-mixer1.2                 - Mixer library for Simple DirectMedia Layer
i   libsdl-mixer1.2:i386            - Mixer library for Simple DirectMedia Layer
i A libsdl-net1.2                   - Network library for Simple DirectMedia Lay
i   libsdl-net1.2:i386              - Network library for Simple DirectMedia Lay
i   libsdl-net1.2-dbg               - Network library for Simple DirectMedia Lay
i   libsdl-net1.2-dev               - Network library for Simple DirectMedia Lay
i A libsdl-pango1                   - text rendering with Pango in SDL applicati
i   libsdl-perl                     - SDL bindings for the Perl language        
i A libsdl-sge                      - extension of graphic functions for SDL mul
i   libsdl-sge-dev                  - extension of graphic functions for the SDL
i   libsdl-sound-gst                - SDL_sound bindings for GNU Smalltalk      
i A libsdl-sound1.2                 - Sound library for Simple DirectMedia Layer
i   libsdl-ttf-gst                  - SDL_ttf bindings for GNU Smalltalk        
i A libsdl-ttf2.0-0                 - TrueType Font library for Simple DirectMed
i   libsdl-ttf2.0-0:i386            - TrueType Font library for Simple DirectMed
i   libsdl-ttf2.0-dev               - TrueType Font library for Simple DirectMed
i A libsdl1.2-dev                   - Simple DirectMedia Layer development files
i   libsdl1.2debian                 - Simple DirectMedia Layer                  
i   libsdl1.2debian:i386            - Simple DirectMedia Layer                  
i A libsdl2-2.0-0                   - Simple DirectMedia Layer                  
i   libsdl2-dbg                     - Simple DirectMedia Layer debug files      
i   libsdl2-dev                     - Simple DirectMedia Layer development files
i   libsdl2-gfx-1.0-0               - drawing and graphical effects extension fo
i   libsdl2-gfx-dbg                 - debugging symbols for SDL2_gfx            
i   libsdl2-gfx-dev                 - development files for SDL2_gfx            
i   libsdl2-gfx-doc                 - documentation files for SDL2_gfx          
i   libsdl2-image-2.0-0             - Image loading library for Simple DirectMed
i   libsdl2-image-dbg               - Image loading library for Simple DirectMed
i   libsdl2-image-dev               - Image loading library for Simple DirectMed
i   libsdl2-mixer-2.0-0             - Mixer library for Simple DirectMedia Layer
i   libsdl2-mixer-dbg               - Mixer library for Simple DirectMedia Layer
i   libsdl2-mixer-dev               - Mixer library for Simple DirectMedia Layer
i   libsdl2-net-2.0-0               - Network library for Simple DirectMedia Lay
i   libsdl2-net-dbg                 - Network library for Simple DirectMedia Lay
i   libsdl2-net-dev                 - Network library for Simple DirectMedia Lay
i   libsdl2-ttf-2.0-0               - TrueType Font library for Simple DirectMed
i   libsdl2-ttf-dbg                 - TrueType Font library for Simple DirectMed
i   libsdl2-ttf-dev                 - TrueType Font library for Simple DirectMed

2) 确保我设置了适当的环境变量SDL_VIDEODRIVER。[在研究另一篇帖子后得知,如果不设置此变量,pygame将无法正常工作]

>~set | grep 'SDL'
SDL_VIDEODRIVER=x11
< p >[补充一下之前的内容:我运行了一个简单的编译好的C文件,演示了在libSDL中呈现图像的窗口,这个可以工作得很好!]< /p> < p >在双重检查libSDL已安装/驱动器的环境变量已设置之后,我下载了三个不同的游戏从pygame网站。这个特定的错误仍然存在。我被卡住了,需要任何帮助来解决这个问题并让pygame正常工作。非常感谢您的时间。< /p>

你是用apt-get、pip还是运行setup.py安装pygame的?如果你使用了apt-get,我认为它应该会“自动工作”……而且可能也适用于“pip”。 - Joran Beasley
我使用了 apt-get install python-pygame。没有想到使用其他的安装方法。也许我会尝试一下其他的方法。不过似乎已经成功安装了,因为我能够运行 Python 然后输入 import pygame; pygame.init(),而不是得到一个错误。谢谢! - JLP1990
抱歉,我无法提供更多帮助 :/ - Joran Beasley
1
如果您有时间和意愿,可以考虑将您的问题分成一个答案帖子(您是如何解决的)和一个问题帖子(在您解决它之前的更新问题)。如果您没有时间或意愿这样做,我很高兴您已经解决了这个问题! :D - Augusta
1个回答

1
这是来自问题的内容,已经移动到此处以更好地呈现答案。

好的。我已经在我的Linux系统上成功地安装了pygame。我因为其他原因不得不重新分区,但是我想在新的安装中遵循下面的步骤,并最终让它工作:(链接描述头文件问题,libv4l-dev)

  1. 在命令行中输入以下内容安装所有依赖项: ~> apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev
  2. 运行SDL配置命令: ~> sdl-config --cflags --libs
  3. 进入pygame-1.9.1release文件夹,运行: ~> python config.py 查看是否缺少任何依赖项。 此时,我缺少:SMPEG、PORTMIDI和PORTTIME。 我只是查找了这些并使用Synaptic软件包管理器进行下载。
  4. 之后再次运行python config.py,显示我已经有了 所有必需的依赖项。
  5. 然后我运行sudo python setup.py install,出现了一些错误 关于找不到头文件。发现另一个 StackExchange帖子详细介绍了如何解决这个特定问题: ~> sudo apt-get install libv4l-dev ~> cd /usr/include/linux ~> sudo ln -s ../libv4l1-videodev.h videodev.h
  6. 再次运行sudo python setup.py,它就可以工作了。 通过运行python,然后检查版本来确认这一点 import pygame,然后是pygame.version.ver()... 并快速运行其他人制作的游戏。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接