Ask Your Question

How do I fix issue with no window opening with cv2.imshow?

asked 2020-03-12 17:02:08 -0500

PaulSpon gravatar image

updated 2020-10-21 04:17:42 -0500

I successfully use cv2.imread to read an image. I can display in the console using matplotlib.imshow. When I use cv2.imshow, nothing happens, no errors, no window opens. Script ends normally, but no image. I tried using different integers with cv2.waitKey() and leaving it empty, but no luck. Works great on Windows, but not on my Mac.

Using Python 2.7, Spyder 3.3.6, openCV 4.2.0.

import cv2
import numpy as np
import matplotlib.pyplot as plt
img =cv2.imread('/Users/Paul/Documents/Photos/F15.jpg',cv2.IMREAD_GRAYSCALE)
edit retag flag offensive close merge delete


You must check image after read :

if img is None:
     print("Check file path")

Python 2 is dead :

LBerger gravatar imageLBerger ( 2020-03-13 01:56:34 -0500 )edit

The path is fine. As I said, the image displays properly using matplotlib.

The code is working on Python 2.7 and 3.7 on my personal computers. This appears to be Mac related.

PaulSpon gravatar imagePaulSpon ( 2020-03-13 12:19:45 -0500 )edit

Installed Python 3.7. This did not resolve my issue.

PaulSpon gravatar imagePaulSpon ( 2020-03-13 15:50:25 -0500 )edit

Ok it's mac so read this and may be you will find something to solve your problem

LBerger gravatar imageLBerger ( 2020-03-13 16:22:53 -0500 )edit

I read through the items and did additional searches. Nothing is crashing and there were no errors, so the threads didn't help.

Now getting a new error which I will research on my own. Several identical lines of:

[IPKernelApp] WARNING | No such comm: 7a6fd824656d11ea9fc0a45e60dd0c91

PaulSpon gravatar imagePaulSpon ( 2020-03-13 17:44:00 -0500 )edit

did you resolve it ??? Please help me even I am facing the same problem

msd gravatar imagemsd ( 2020-11-13 09:07:10 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2020-12-15 02:51:46 -0500

Yes I'm facing the same issue on mac but it's only because of the editor which we are using. I tried it on VS Code, the same problem occurred with me. When I used the same code on IDLE it worked fine, and the windows appeared. So I think there's a GUI problem with the code editor. Guys, just put your code in IDLE and GUI will open. If any of you figure out how to resolve this GUI not opening ( imshow() not opening the window ) problem in VS code, do let me know :)

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-03-12 16:59:27 -0500

Seen: 12,512 times

Last updated: Mar 13 '20