Search code examples
pythonopencvcommand-line-interfacepython-idle

IDLE can't find cv2, CLI Python imports it correctly


I am able to import the OpenCV python bindings (cv2) fine when running Python from the command line, but I receive the standard 'no module named cv2' from IDLE when I import there.

I checked the Path Browser in IDLE, and noticed that it doesn't match my .bashrc PYTHONPATH.

That said, I copied the cv2 binding files into one of the directories specified in the Path Browser, and IDLE still can't find it.

Two questions: 1) Has anyone run into this circumstance? 2) Does IDLE have a PYTHONPATH different from the rest of the system?


Solution

  • When you launch GUI applications on OS X (.app bundles), no shell is involved and shell profile scripts are not used. IDLE.app is no exception. So any environment variables defined there are not available to the GUI app. The best solution is to properly install your third-party packages into the standard locations included in Python's module search path, viewable as sys.path, and not use PYTHONPATH at all. Another option in this case is to launch IDLE from a terminal session shell, e.g. /usr/local/bin/idle2.7.