python-3.x - 如何修复 docker 上与 pygame 相关的“pygame.error:没有可用的视频设备”错误?
问题描述
我正在尝试使用 pygame 脚本运行图像,但出现错误: pygame.error: No available video device
pygame 脚本在我的计算机上运行良好(Linux、Ubuntu 16.04、32 位,我使用以下步骤安装了 docker:https : //stackoverflow.com/a/48881019/6796652),当我将它包含在 dockerfile 图像中时会出现问题.
我阅读了一些相关的帖子,因为这个pygame 项目将无法运行:“pygame.error: No available video device”,但我在 dockerfile 中找不到相同的问题。
这是 pygame 脚本的一部分:
import pygame
def main():
pygame.init()
screen=pygame.display.set_mode((400,600))
# Here are more code...
# And finally
pygame.quit()
main()
我尝试包括这部分,因为这篇文章说https://stackoverflow.com/a/53623914/6796652
from pygame.locals import *
这是我的 Dockerfile:
FROM python:3
WORKDIR /myfolder
COPY main.py someimage.png wallpaper.jpg requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "./main.py" ]
我也尝试使用 Ubuntu 映像,但结果完全相同:
FROM ubuntu:14.04
WORKDIR /myfolder
COPY main.py someimage.png wallpaper.jpg requirements.txt ./
RUN apt-get update
RUN apt-get install python-pip python-dev build-essential -y
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "./main.py" ]
甚至,如文档所述,安装 Python 3.x 的依赖项:http: //www.pygame.org/wiki/CompileUbuntu结果是一样的
FROM python:3
WORKDIR /DefeatTheBat
COPY bat.png main.py wallpaper.jpg requirements.txt ./
RUN apt-get update && apt-get install -y \
python3-dev -y \
python3-setuptools -y \
python3-numpy -y \
python3-opengl -y \
libsdl-image1.2-dev -y \
libsdl-mixer1.2-dev -y \
libsdl-ttf2.0-dev -y \
libsmpeg-dev -y \
libsdl1.2-dev -y \
libportmidi-dev -y \
libswscale-dev -y \
libavformat-dev -y \
libavcodec-dev -y \
libtiff5-dev -y \
libx11-6 -y \
libx11-dev -y \
fluid-soundfont-gm -y \
timgm6mb-soundfont -y \
xfonts-base -y \
xfonts-100dpi -y \
xfonts-75dpi -y \
xfonts-cyrillic -y \
fontconfig -y \
fonts-freefont-ttf -y \
libfreetype6-dev -y
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "./main.py" ]
还有requirements.txt:
pygame==1.9.5
我收到此错误:
screen=pygame.display.set_mode((400,600))
pygame.error: No available video device
什么时候应该显示窗口。如果我在我的交互式 python shell 中尝试该部分,它工作得很好。
我该如何修复这个 dockerfile 图像?
解决方案
推荐阅读
- c++ - 在单独的函数中获取二维数组的数据?
- node.js - Twilio - 我可以转接电话,以便部门的其他人可以接听电话吗?
- swift - 如何在 MacOS 上滚动时修复 SwifyUI 列表的重影?
- javascript - JS 无限循环保护,如何在没有节点或 web-worker 的情况下使用带有 DOM 的 babel-standalone 插件?
- r - 拟合“gls”模型后将“joint_tests”映射到列表
- r - 根据具有重复度量的其他列上的条件向列添加值
- visual-studio-code - Visual Studio 不再识别 Python 关键字
- python - 如何获取从 API 生成的 JSON 列表并将其存储在 Python 的哈希图中?
- javascript - 查询自定义数据库(Mongodb)
- c# - 基于 Azure DevOps 构建的 Blazor Wasm