我遇到了一个问题,尝试运行一个非常简单的Python脚本,但是出现了这个错误:
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
脚本代码如下:
import cv2
img = cv2.imread('00-puppy.jpg')
while True:
cv2.imshow('Puppy',img)
if cv2.waitKey(1) & 0xFF == 27:
break
cv2.destroyAllWindows()
然而,这个Notebook代码在JupyterLab中可以运行:
import cv2
img = cv2.imread('00-puppy.jpg')
cv2.imshow('Puppy', img)
cv2.waitKey()
我使用的是macOS,Anaconda和JupyterLab。希望能够得到解决这个问题的帮助。谢谢!
brew info qt
,你可以看到它安装在哪里以及版本号。我认为问题是 Python 没有在正确的位置查找它,因此必须设置一个环境变量。 - superheroopencv-python-headless
而不是opencv-python
解决了我在 Mac 上遇到的相同问题(我只需执行pip install opencv-python-headless
)。我认为值得一试。 - hideya