pythonwindowsterminalpycharmimporterror

Windows console instantly closes if an installed module is imported, but works in PyCharm


I'm not sure why, but any python file that has opencv imported makes the Windows console close instantly and the program to exit. No errors, no freezes, the window simply closes.

However, in an IDE (I am using Pycharm), the program works as expected.

Here's a simple code sample to replicate the issue:

import cv2

print("hello world")

The opencv-python version I have installed is 4.11.0.86 if that helps.

I don't know what to do. Any help is appreciated.


Solution

  • open-cv might be installed in virtual environment in pycharm.

    Try python -m pip install opencv-python