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

时间:2015-09-11 23:37:12

标签: python pygame

更新1:我卸载,重新安装并按照Pygame网站上的说明安装依赖项/构建Pygame。事实证明我缺少依赖关系,因为Python指示我何时尝试运行setup.py脚本:

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位。肉桂版:2.6.13。显卡:英特尔公司Broadwell-U集成显卡。 7.7 GiB Memory,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设置了适当的envvar。 [在研究另一篇文章后,表明需要设置此变量或pygame无法正常工作]

>~set | grep 'SDL'
SDL_VIDEODRIVER=x11

[添加到前者:我运行了一个简单的编译.c文件,演示了一个窗口,在libSDL中渲染了图像,并且工作正常!]

安装了libSDL的双重检查后,设置了驱动程序的envvar,这个特殊错误在我从pygame站点下载的三个不同游戏中持续存在。我在这一点上非常难过,并且非常感谢有关如何解决这个问题以及让pygame工作的任何帮助。非常感谢你的时间。

1 个答案:

答案 0 :(得分:1)

这是问题所在;它被移到这里以进一步揭露答案。

好的。我让pygame在我的Linux安装上工作。我不得不重新分配一个无关的原因,但我想这样做之后我在新的安装上执行了这些步骤,最后让它工作:(链接描述下面的头文件问题,libv4l-dev)

  1. 在命令行中输入以下命令安装所有依赖项: 〜&GT; apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev
  2. 运行SDL配置命令: 〜&GT; sdl-config --cflags --libs
  3. 输入pygame-1.9.1release的文件夹,然后运行: 〜&GT; python config.py 看看我错过了什么,如果有的话,依赖关系。 此时,我失踪了:SMPEG,PORTMIDI和PORTTIME。 我只是查看了这些并使用下载它们 Synaptic Package Manager。
  4. 之后再次运行python config.py显示我有 所有必需的依赖。
  5. 然后我跑了sudo python setup.py install并遇到了一些错误 关于未找到的头文件。发现另一个 StackExchange帖子详细说明了如何解决此特定问题: 〜&GT; sudo apt-get install libv4l-dev 〜&GT; cd /usr/include/linux 〜&GT; sudo ln -s ../libv4l1-videodev.h videodev.h
  6. 再次跑sudo python setup.py,它有效。 通过运行python确认,然后检查版本 import pygame后跟pygame.version.ver() ... 并迅速运行其他人制作的游戏。