opencv / opencv/opencv-python

Uninstalling opencv-python prevents opencv-contrib-python from working.

Open
#962 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

Expected behaviour

If both versions of opencv are installed in an environment, uninstalling one version shouldn't mess with the other version.

Yes, I'm very aware that you are not supposed to download both versions. And the readme does state If you installed multiple different packages in the same environment, uninstall them all with pip uninstall and reinstall only one package. But if it would be possible to skip uninstalling all versions it would be very useful.

I'm in the same situation as this comment. When users download our package with pip install ourpackage, pip downloads dependency A, which has opencv-python as a dependency, and dependency B, which has opencv-contrib-python as a dependency. As far as I can tell, there is no way to prevent these downloads from pip. Our goal is to make installing our package as easy as possible, and adding multiple pip steps of uninstalling and reinstalling is intimidating for non-technical users. It also takes up support time for us, since users will inevitably try to uninstall only one package. Resolving this installation issue would be very helpful in reducing the install instructions for packages which cannot avoid this opencv conflict.

Actual behaviour

Uninstalling opencv-python when opencv-contrib-python is installed prevents opencv-contrib-python from working properly. For example, import cv2, cv2.VideoCapture(0) errors with AttributeError: module 'cv2' has no attribute 'VideoCapture'.

Steps to reproduce
  • example code
pip install opencv-python opencv-contrib-python
pip uninstall opencv-python
python -c "import cv2; cv2.VideoCapture(0)"

I initially thought both packages shared the cv2 folder in site-packages and uninstalling one deleted that folder, but that appears not to be the case. (EDIT) The contents of the folder do change quite a bit though. In a new conda environment with both opencv versions installed:

$ ls $CONDA_PREFIX/lib/python3.11/site-packages
README.txt
_distutils_hack
cv2 ### Both dist-info folders seem to reference this
distutils-precedence.pth
numpy
numpy-1.26.4.dist-info
opencv_contrib_python-4.9.0.80.dist-info
opencv_python-4.9.0.80.dist-info
pip
pip-23.3.1-py3.11.egg-info
pkg_resources
setuptools
setuptools-68.2.2-py3.11.egg-info
wheel
wheel-0.41.2.dist-info
$ ls $CONDA_PREFIX/lib/python3.11/site-packages/cv2
Error			flann			phase_unwrapping
LICENSE-3RD-PARTY.txt	ft			plot
LICENSE.txt		gapi			ppf_match_3d
__init__.py		hfs			py.typed
__init__.pyi		img_hash		quality
__pycache__		intensity_transform	rapid
aruco			ipp			reg
barcode			kinfu			rgbd
bgsegm			large_kinfu		saliency
bioinspired		legacy			samples
ccm			line_descriptor		segmentation
colored_kinfu		linemod			stereo
config-3.py		load_config_py2.py	structured_light
config.py		load_config_py3.py	text
cuda			mat_wrapper		typing
cv2.abi3.so		mcc			utils
data			misc			version.py
datasets		ml			videoio_registry
detail			motempl			videostab
dnn			multicalib		wechat_qrcode
dnn_superres		ocl			xfeatures2d
dpm			ogl			ximgproc
dynafu			omnidir			xphoto
face			optflow
fisheye			parallel

After running pip uninstall opencv-python:

$ ls $CONDA_PREFIX/lib/python3.11/site-packages
README.txt
_distutils_hack
cv2 ### but it isn't removed when uninstalling one version
distutils-precedence.pth
numpy
numpy-1.26.4.dist-info
opencv_contrib_python-4.9.0.80.dist-info
pip
pip-23.3.1-py3.11.egg-info
pkg_resources
setuptools
setuptools-68.2.2-py3.11.egg-info
wheel
wheel-0.41.2.dist-info
$ ls $CONDA_PREFIX/lib/python3.11/site-packages/cv2
bgsegm			kinfu			quality
bioinspired		large_kinfu		rapid
ccm			legacy			reg
colored_kinfu		line_descriptor		rgbd
datasets		linemod			saliency
dnn_superres		mcc			stereo
dpm			motempl			structured_light
dynafu			multicalib		text
face			omnidir			videostab
ft			optflow			wechat_qrcode
hfs			phase_unwrapping	xfeatures2d
img_hash		plot			ximgproc
intensity_transform	ppf_match_3d		xphoto

Diff between the two versions of the cv2 folder, sorted (diff old new):

1,8d0
< Error
< LICENSE-3RD-PARTY.txt
< LICENSE.txt
< __init__.py
< __init__.pyi
< __pycache__
< aruco
< barcode
13,17d4
< config-3.py
< config.py
< cuda
< cv2.abi3.so
< data
19,20d5
< detail
< dnn
25,26d9
< fisheye
< flann
28d10
< gapi
32d13
< ipp
38,40d18
< load_config_py2.py
< load_config_py3.py
< mat_wrapper
42,43d19
< misc
< ml
46,47d21
< ocl
< ogl
50d23
< parallel
54d26
< py.typed
60,61d31
< samples
< segmentation
65,68d34
< typing
< utils
< version.py
< videoio_registry
  • operating system
    Mac Monterrey 12.6.2
  • architecture (e.g. x86)
    Arm64
  • opencv-python version
    opencv_python-4.9.0.80
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented pip install and uninstall commands in a clean environment, then inspect the package metadata and build-toolchain behavior described in the issue. The work is done when uninstalling one OpenCV package no longer breaks the remaining package, with the reported cv2.VideoCapture example continuing to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.