一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 17|回复: 0

在使用 Docker 打包 Python 环境时,如何解决系统依赖缺失导致的反复运行失败?

[复制链接]

2万

主题

2万

帖子

6万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
60838
发表于 3 天前 | 显示全部楼层 |阅读模式
将Python环境打包到Docker时,我遇到了许多问题。例如,部署PyQt环境时,除了requirements.txt列出的依赖之外,还需要额外安装许多依赖,比如:
```bash
sudo apt install pyqt5*
sudo apt-get install libxcb-xinerama0 libxcb-xinerama0-dev
export QT_QPA_PLATFORM=xcb
pip uninstall opencv-python
pip install opencv-python-headless
```
这些依赖是在WSL2的Ubuntu系统中摸索出来的,并让程序成功启动。然而,无法一次性确定所有缺失的依赖,每次构建完Docker镜像后都需要运行一次才能发现报错,效率极低。尤其是在Python环境构建时间较长的情况下,每次耗费十分钟,非常影响开发进度。
目前我已经尝试了十多次打包,每次报错内容都不相同。另外,这些错误不是在打包镜像时出现的,而是在运行容器时发生的。
例如,运行时会遇到以下错误:
```cmd
gt.qpa.xcb:could not connect to display
qt.qpa.plugin:Could not load the Qt platform plugin "xcb" in "even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are:eglfs,linuxfb,minimal,minimalegl,offscreen,vnc,wayland-egl,wayland,wayland-xcomposite-egl,wayland-xcomposite-glx,webgl,xcb.
```
希望能够找到解决方案,提高打包效率。
我的环境配置如下:
* WSL2: Ubuntu-22.04
* Docker: python:3.10-slim
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-9-28 23:28 , Processed in 0.063662 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表