简体   繁体   中英

pyqt5: This application failed to start because no Qt platform plugin could be initialized - installation problem?

I am working on Ubuntu 18.04 (as a Windows 10 subsystem for linux). When I try running code that uses pyqt5 it throws the error:

" qt.qta.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, xcb.

Aborted "

as in the image image of error message (the error is definitely connected to pyqt5). I have found many posts that suggest to:

  1. Go to => Python38>lib>site-packages>PyQt5>Qt>plugins
  2. In plugins copy platforms folder
  3. After that go to Python38>lib>site-packages>PyQt5_tools>Qt>bin
  4. paste folder here. Do copy and replace.

but it seems like there is no Qt folder in pyqt5_tools on my computer. I have removed and installed back pyqt5, pyqt5-tools, pyqt5-plugins several times but it does not work. Can it be connected to the fact that I am using a subsystem? (I have downloaded pyqt5 both on Windows and on Ubuntu). Any suggestions to solve this problem?

The error relates to a missing requirement for one or multiple XCB-related libraries, which needs to be fulfilled on X11 for Qt to function properly. For a full list of XCB libraries check here .

I would suggest that, instead of copying files left and right, you first try reinstalling PyQt5 via pip . I've had a similar experience with conda , where PySided2 was not working due to a missing shiboken , which I had to install via pip .

In addition you may want to try conda (eg Anaconda or Miniconda). Last but not least, if this is the only problem you have, you may attempt to install the required XCB libraries. This is however tricky, since the version your distro provides may be different from the rest that the pip installation has.

A safe way for installing PyQt5 is simply using the package manager of your distro inside WSL. Since it's a virtualized system I'd assume that it's created solely for the purpose of working on a PyQt5 project and after that it will be deleted. Tainting the clean initial setup should therefor not be an issue.

显示此错误是因为您在基础环境中安装了 PyQt,因此删除 anaconda 并重新安装它,然后尝试创建一个新环境并在其中工作。

In my specific case the issue is caused by the WSL, that has no access to the graphic part of the computer. I performed a dual boot on my computer in order to proceed, because I could not find a way to solve the issue.

Someone suggested to run "xhost +local:" first.

I had the same issue, Ubuntu 18 on WSL as well.

I solved following @rbaleksandar's suggestion.

conda install -c anaconda pyqt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM