Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
philipqueen opened this issue Mar 14, 2024 · 0 comments
Open
4 tasks done

Comments

@philipqueen
Copy link

philipqueen commented Mar 14, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant