【发布时间】:2021-01-05 06:44:57
【问题描述】:
我正在尝试执行使用 PyQT4 的 python 文件
我在服务文件下面运行
[Unit]
Description = Test
After=multi-user.target
[Service]
Type=simple
ExecStart = /usr/bin/python3 /home/nvidia/main
Restart=on-abort
[Install]
WantedBy =multi-user.target
此文件位于/lib/systemd/system/test.service 下,我将通过systemctl start Test 启动此服务
但启动此服务会导致错误标记为cannot connect to X Server, failed with result exit-code
我正在使用脚本
#!/usr/bin/python
#################################################################################################################################################
# Author = Rucha
# Version = V 2.0.3
# Class = PR01 OOP
# Module = pyqt4
# Date = Jan 02 2021
#################################################################################################################################################
import sys
from PyQt4 import QtGui
######################################################################################################################################
class MainWindow:
def __init__(self):
self.vbox = QtGui.QHBoxLayout()
def Title(self,Window,Name):
Window.setWindowTitle(Name)
def window(self):
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.setGeometry(800,800,500,500)
self.Title(w,"Test")
w.show()
sys.exit(app.exec_())
MainWindow1 = MainWindow()
MainWindow1.window()
【问题讨论】:
-
python脚本是做什么的?它真的需要图形服务器(X11)来运行吗?你能给我们提供它的代码,或者至少是一个minimal, reproducible example吗?
-
是的,我已将脚本添加到我的问题@musicamante
标签: linux pyqt4 ubuntu-18.04 xserver