【问题标题】:Is it possible to run pygame in ubuntu vps server?是否可以在 ubuntu vps 服务器上运行 pygame?
【发布时间】:2017-06-27 10:41:39
【问题描述】:

我尝试在 ubuntu 16.04 vps 服务器上运行 pygame。它适用于“ssh -X root@server_ip”。但是pygame在没有-X的ssh连接时会报错。

    pygame.display.set_mode((self.w, self.h),DOUBLEBUF|OPENGL)  
    pygame.error: No available video device

我在服务器上安装了 x11 并且它工作正常。即使如此 pygame 错误仍在继续。

code :
        os.environ['SDL_VIDEODRIVER'] = 'x11'
        pygame.init()
        pygame.display.set_mode((self.w, self.h),DOUBLEBUF|OPENGL)

x11 status:

root@vps423325:~# service x11-common status 
● x11-common.service - LSB: set up the X server and ICE socket directories
   Loaded: loaded (/etc/init.d/x11-common; bad; vendor preset: enabled)
   Active: active (exited) since Tue 2017-06-27 00:15:02 CEST; 11h ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1002 ExecStart=/etc/init.d/x11-common start (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0

Jun 27 00:15:02 vps423325 systemd[1]: Starting LSB: set up the X server and ICE     socket directories...
Jun 27 00:15:02 vps423325 x11-common[1002]:  * Setting up X socket directories...
Jun 27 00:15:02 vps423325 x11-common[1002]:    ...done.
Jun 27 00:15:02 vps423325 systemd[1]: Started LSB: set up the X server and ICE socket       directories.

【问题讨论】:

  • -X 转发您连接的计算机的图形会话。这样的会话是必需的,通过 SSH 或者您需要服务器上的本地图形登录会话或虚拟帧缓冲区。

标签: python linux opengl ssh pygame


【解决方案1】:

您必须安装 Xming X Server for Windows 才能使其工作并在您的机器上显示内容。 从这里下载并安装 XMing:https://sourceforge.net/projects/xming/,然后重试。

【讨论】:

  • 我的目的是将 pygame 脚本作为后台任务运行,由 http 请求触发。我认为,如果 pygame 脚本将在没有 -X 的 ssh 终端中运行,它可以作为服务器脚本运行。是吗错了吗?
  • 所以你需要无头运行pygame,你将视频驱动设置为x11os.environ['SDL_VIDEODRIVER'] = 'x11'而不是设置为x11尝试将其设置为dummyfbcon .
  • 在 os.environ['SDL_VIDEODRIVER'] = 'x11' 更改 os.environ['SDL_VIDEODRIVER'] = 'dummy' 后,我收到一个新错误“pygame.error: OpenGL not available” .我用“sudo apt-get install python-opengl”安装了python-opengl。此外glxinfo命令给出输出“错误:无法打开显示”。 OpenGL配置有错误吗?