Docker内运行GUI程序¶
Docker内运行GUI程序¶
- 开放权限允许程序访问X11的显示接口
apt-get install x11-xserver-utils xhost +
- 启动docker时添加额外选项
进入docker后确认
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE
DISPLAY
环境变量的值,一般都是unix:0
,如果不是的话,可以手动export DISPLAY=unix:0
如果使用Opencv-Python中的cv2.imshow()
出现了错误可以降低OpenCV的版本来解决qt.qpa.xcb: could not connect to display unix qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/usr/local/lib/python3.7/dist-packages/cv2/qt/plugins" 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: xcb.
pip install opencv-python==4.1.2.30