简体   繁体   中英

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

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 would appreciate any help with this issue. Thanks!

尝试安装

pip3 install opencv-python==4.1.2.30  

For Ubuntu users,

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

(I'm using OpenCV 4.4)

For me, it worked by using a opencv-python version prior to 4.2 version that just got released. The new version ( 4.2.0.32 ) 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 4.1.2.30 , which works like charm without doing anything else.

It works for opencv-contrib-python too.

这可以解决安装python-opencv-headless而不是python-opencv

Same issue here. No answer, but it's appearing in a similar setup. I've tried throwing many solutions at it:

  • Installing QT from brew,
  • Reinstalling from: qt.io/download-qt-installer
  • Installing from pip (using virtual environments)
  • Explicitly setting changing the environment variables
    • QT_PLUGIN_PATH="/Users/halopend/.qt/5.14.1/clang_64/plugins/"
    • QT_QPA_PLATFORM_PLUGIN_PATH="/Users/halopend/.qt/5.14.1/clang_64/plugins/platforms/"

Sometimes the issue appeared to be opencv having qt included within it which classed with an externally defined qt, but I'm not sure.

Anyway, not sure if that will help you, but at least you have a few ideas of where to look.

经过多次反复试验,对我来说,它适用于卸载和安装numpyopencv

I met the same issue. I agree with Simran Singh. This issue comes from the recent update.

Quote from pacjin79 on Github:"If you are on a mac, make sure you install opencv-python-headless instead of opencv-python to avoid these errors." link

I personally solved the issue by doing so. Hope this works for you.

This issue appears in the latest version of Opencv. I recommend downgrading the version or installing Qt in a specific directory.

Try

pip install opencv-python==4.1.2.30  

Facing the same issue with PyQt5 and solving it by using PyQt6==6.3.1 and opencv-python==4.6.0.66 .

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