Error when installing opencv with Python Interactor on mac

Hi everyone,

I have MacOS 10.14. I’m trying to install opencv in the python interactor by this code:

from slicer.util import pip_install
pip_install(“opencv”)

I get this error:

ERROR: Could not find a version that satisfies the requirement opencv (from versions: none)
ERROR: No matching distribution found for opencv
WARNING: You are using pip version 20.1.1; however, version 20.3.3 is available.
You should consider upgrading via the ‘/Applications/Slicer.app/Contents/bin/./python-real -m pip install --upgrade pip’ command.
Traceback (most recent call last):
File “”, line 1, in
File “/Applications/Slicer.app/Contents/bin/Python/slicer/util.py”, line 2569, in pip_install
_executePythonModule(‘pip’, args)
File “/Applications/Slicer.app/Contents/bin/Python/slicer/util.py”, line 2545, in _executePythonModule
logProcessOutput(proc)
File “/Applications/Slicer.app/Contents/bin/Python/slicer/util.py”, line 2517, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[’/Applications/Slicer.app/Contents/bin/…/bin/PythonSlicer’, ‘-m’, ‘pip’, ‘install’, ‘opencv’]’ returned non-zero exit status 1.

Also regarding the Warning that I get for the update for pip when I open the python real, it is not editable to be able to put this code:

/Applications/Slicer.app/Contents/bin/./python-real -m pip install --upgrade pip

Thanks for your help.

This doesn’t exactly answer your question, but you could install the SlicerOpenCV extension, which will install opencv and python bindings.

I searched for SlicerOpenCV in the slicer extensions but I couldn’t find it.

I believe the correct name to use to pip install OpenCV is “opencv-python”. So in Slicer it would be slicer.util.pip_install("opencv-python") instead of slicer.util.pip_install("opencv") as you tried.

See opencv-python · PyPI

2 Likes