PyQt5 Could not connect to display

被刻印的时光 ゝ 提交于 2019-12-25 04:17:17

问题


to learn python I decided to make a small GUI that will interact with a web API. So without much thinking I created a virtual machine with Vagrant (ubuntu/trusty64) and installed PyQt5. I made a small script to create a window (here it is)

import sys
from PyQt5 import QtWidgets

app = QtWidgets.QApplication(sys.argv)

main_window = QtWidgets.QMainWindow()
main_window.show()

sys.exit(app.exec_())

When I executed my script I ended up with this error

QXcbConnection: Could not connect to display

So I guess the problem comes from the fact that I'm using a virtual-machine without a display. Isn't there a way to make it use my Windows display just to render my program? Or do I need to install a VM with virtualbox?

Thanks for your time.


回答1:


When provisioning your VM with Vagrant, you may specify to boot to GUI, such as:

config.vm.provider "virtualbox" do |v|
  v.gui = true
end

More information here

This will then launch the Qt app, using the VM's display.



来源:https://stackoverflow.com/questions/29924997/pyqt5-could-not-connect-to-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!