Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This application failed to start because no Qt platform plugin could be initialized

I am new to programming and I am stuck trying to run a very simple Python script, getting this error:

qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

zsh: abort      python3 mypuppy1.py

The script code is:

import cv2
img = cv2.imread('00-puppy.jpg')
while True:
    cv2.imshow('Puppy',img)
    if cv2.waitKey(1) & 0xFF == 27:
        break
cv2.destroyAllWindows()

However this Notebook code works in JupyterLab:

import cv2
img = cv2.imread('00-puppy.jpg')
cv2.imshow('Puppy', img)
cv2.waitKey()

I am on macOS, using Anaconda and JupyterLab.

I have tried googling the issue but either I couldn't implement the solutions right or they just do not work for me as most of them are for Windows' users.

I would appreciate any help with this issue. Thanks!

like image 636
Nick Foley Avatar asked Feb 03 '20 15:02

Nick Foley


People also ask

How do I install Qt plugins?

Note: You can install only plugins that are supported by your Qt Creator version. To install plugins: Select Help > About Plugins > Install Plugins. In the Source dialog, enter the path to the archive or library that contains the plugin.

How do you fix this application failed to start because it could not find or load the Qt platform plugin windows?

In order to fix the “Application failed to start because no Qt platform plugin could be initialized” error, you should uninstall all recently installed applications and see if that solves your problem in normal mode.

What is a Qt plugin?

Qt provides a simple plugin interface which makes it easy to create custom database drivers, image formats, text codecs, styles and widgets as stand-alone components. Warning: Qt 3.0. 5 introduces changes into some aspects of plugins, in particular regarding loading, path handling and library versions.

What is XCB Qt?

On Linux, the xcb QPA (Qt Platform Abstraction) platform plugin is used. It provides the basic functionality needed by Qt GUI and Qt Widgets to run against X11.


2 Answers

Try installing

pip3 install opencv-python==4.1.2.30  
like image 57
khaidem Avatar answered Oct 24 '22 13:10

khaidem


For Ubuntu users,

sudo apt-get install qt5-default fixes the issue.

(I'm using OpenCV 4.4)

like image 28
WhaSukGO Avatar answered Oct 24 '22 14:10

WhaSukGO