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!
For me, it worked by using a
opencv-python version prior to
4.2 version that just got released. The new version (
188.8.131.52) released on Feb 2, 2020 seems to have caused this breaking change and probably expects to find Qt at a specific location (
Users/ directory) as pointed by other answers.
You can try either manually installed from qt.io as suggested and making sure you get a
.qt directory under yours
Users directory, or you can use version
184.108.40.206, which works like charm without doing anything else.
It works for opencv-contrib-python too.
Answered By – Simran Singh
Answer Checked By – Katrina (BugsFixing Volunteer)