cv2 not work after install mediapipe library - python

I want to make handtracker program using python but the tutorial tell me to install mediapipe library, then I installed it. Before that it's okay using cv2 to stream my camera, but after installing mediapipe, the cv2 doesn't work
here the message :
>>>import cv2
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 175, in bootstrap
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 28, in __load_extra_py_code_for_module
py_module = importlib.import_module(module_name)
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\gapi\__init__.py", line 290, in <module>
cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import) ```
I tried to install opencv again but always get this message :
Requirement already satisfied: numpy>=1.19.3 in c:\users\windows\appdata\local\programs\python\python39\lib\site-packages (from opencv-python) (1.21.1)
but the problem still there. How do I fix it?
Edited : this is my pip list
C:\Users\windows>pip list
Package Version
--------------------- --------
absl-py 1.1.0
attrs 21.4.0
cycler 0.11.0
fonttools 4.33.3
kiwisolver 1.4.2
matplotlib 3.5.2
mediapipe 0.8.10
numpy 1.21.1
opencv-contrib-python 4.6.0.66
opencv-python 4.5.3.56
packaging 21.3
Pillow 8.3.1
pip 22.1.2
protobuf 4.21.1
pygame 2.1.2
pyparsing 3.0.9
python-dateutil 2.8.2
pyzbar 0.1.8
setuptools 56.0.0
six 1.16.0

I have the same situation like above
you can try it:
pip install "opencv-python-headless<4.3"
This command has successfully resolved this situation
Reference:https://github.com/Rudrabha/Wav2Lip/issues/387

In any version(ex: 4.6.0.66), when you install any 2 of 3 packages: opencv-contrib-python, opencv-python-headless, opencv-python, make sure they have the same version. I also got the same error, I found out their versions are different. Then a synchronous update solved the problem.

I have similar problem, and I only have opencv-python installed. The problem is solved by installing opencv-python-headless.
My problem is more complicate than that. Actually the opencv-python is already installed in "root", but when I login as another user (dev), I get the problem as OP.
I can install opencv-python-headless or opencv-contrib-python manually, then the system will work. But if I install them in "root", I sill have the same problem.
So the final solution I use is to reinstall opencv-python in my user environment (dev):
pip3 install --upgrade --force-reinstall opencv-python

I fix such a problem using the following commands.
pip uninstall opencv-contrib-python
pip install opencv-contrib-python

the following solution
pip install "opencv-python-headless<4.3"
fixed the error below when building OpenCV from source!
import cv2
Traceback (most recent call last):
File "", line 1, in
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2_init_.py", line 181, in
bootstrap()
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2_init_.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\ProgramData\Anaconda3\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.

Related

import cv2 error could not do this command [duplicate]

I got below error message when I run model_main_tf2.py on Object Detection API:
Traceback (most recent call last):
File "/content/models/research/object_detection/model_main_tf2.py", line 32, in <module>
from object_detection import model_lib_v2
File "/usr/local/lib/python3.7/dist-packages/object_detection/model_lib_v2.py", line 29, in <module>
from object_detection import eval_util
File "/usr/local/lib/python3.7/dist-packages/object_detection/eval_util.py", line 36, in <module>
from object_detection.metrics import lvis_evaluation
File "/usr/local/lib/python3.7/dist-packages/object_detection/metrics/lvis_evaluation.py", line 23, in <module>
from lvis import results as lvis_results
File "/usr/local/lib/python3.7/dist-packages/lvis/__init__.py", line 5, in <module>
from lvis.vis import LVISVis
File "/usr/local/lib/python3.7/dist-packages/lvis/vis.py", line 1, in <module>
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/__init__.py", line 9, in <module>
from .cv2 import _registerMatType
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)
The weird thing is I run the same code before, it worked well but now it gives me an error.
The same thing occurred to me yesterday when I used Colab. A possible reason may be that the version of opencv-python(4.1.2.30) does not match opencv-python-headless(4.5.5.62). Or the latest version 4.5.5 may have something wrong...
I uninstalled opencv-python-headless==4.5.5.62 and installed 4.1.2.30 and it fixed.
The same thing occurred to me. My status:
C:\Windows\system32>pip list |findstr opencv
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
The version isn't same. So I first uninstall headless:
pip uninstall opencv-python-headless==4.5.5.62
Then reinstall headless 4.5.2.52 with opencv-python package.
pip install opencv-python-headless==4.5.2.52
The problem is the resolved.
Try uninstall and install(version 4.1.2.30) Headless main modules package
!pip uninstall opencv-python-headless
!pip install opencv-python-headless==4.1.2.30
I've had the same issue and the problem was with opencv versioning:
C:\Windows\system32>pip list |findstr opencv
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
As you can see the versions are not the same, so first uninstall headless:
pip uninstall opencv-python==4.5.2.52
And then reinstall opencv-python 4.5.5.62 with opencv-python package:
pip install opencv-python-headless==4.5.5.62
I had the same issue and fixed it by just uninstalling and reinstalling opencv.
pip uninstall opencv-python
pip install opencv-python
After I updated opencv this error occured, in my case
pip list | grep opencv
showed:
opencv-contrib-python 4.5.3.56
opencv-python 4.5.5.62
I upgraded opencv-contrib-python
python -m pip install --upgrade opencv-contrib-python
and the error disappeared.
In case anyone else is having this issue on docker: I was trying to use version 4.3.0.38 and I couldn't find any pre-installed OpenCV on the docker image I was working with. Installing the package with conda install -c conda-forge opencv=4.3.0 instead of pip worked for me.
In my case, the following method was a solution.
pip list | findstr opencv
opencv-contrib-python 4.5.5.64
opencv-python 4.5.3.56
I installed opencv earlier than opencv contribution.
So, I decided to make their versions the same.
pip uninstall opencv-python==4.5.3.56
pip install opencv-python==4.5.5.64
The problem was gone.
Thanks.

cannot import name '_registerMatType' from 'cv2.cv2'

I got below error message when I run model_main_tf2.py on Object Detection API:
Traceback (most recent call last):
File "/content/models/research/object_detection/model_main_tf2.py", line 32, in <module>
from object_detection import model_lib_v2
File "/usr/local/lib/python3.7/dist-packages/object_detection/model_lib_v2.py", line 29, in <module>
from object_detection import eval_util
File "/usr/local/lib/python3.7/dist-packages/object_detection/eval_util.py", line 36, in <module>
from object_detection.metrics import lvis_evaluation
File "/usr/local/lib/python3.7/dist-packages/object_detection/metrics/lvis_evaluation.py", line 23, in <module>
from lvis import results as lvis_results
File "/usr/local/lib/python3.7/dist-packages/lvis/__init__.py", line 5, in <module>
from lvis.vis import LVISVis
File "/usr/local/lib/python3.7/dist-packages/lvis/vis.py", line 1, in <module>
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/__init__.py", line 9, in <module>
from .cv2 import _registerMatType
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)
The weird thing is I run the same code before, it worked well but now it gives me an error.
The same thing occurred to me yesterday when I used Colab. A possible reason may be that the version of opencv-python(4.1.2.30) does not match opencv-python-headless(4.5.5.62). Or the latest version 4.5.5 may have something wrong...
I uninstalled opencv-python-headless==4.5.5.62 and installed 4.1.2.30 and it fixed.
The same thing occurred to me. My status:
C:\Windows\system32>pip list |findstr opencv
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
The version isn't same. So I first uninstall headless:
pip uninstall opencv-python-headless==4.5.5.62
Then reinstall headless 4.5.2.52 with opencv-python package.
pip install opencv-python-headless==4.5.2.52
The problem is the resolved.
Try uninstall and install(version 4.1.2.30) Headless main modules package
!pip uninstall opencv-python-headless
!pip install opencv-python-headless==4.1.2.30
I've had the same issue and the problem was with opencv versioning:
C:\Windows\system32>pip list |findstr opencv
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
As you can see the versions are not the same, so first uninstall headless:
pip uninstall opencv-python==4.5.2.52
And then reinstall opencv-python 4.5.5.62 with opencv-python package:
pip install opencv-python-headless==4.5.5.62
I had the same issue and fixed it by just uninstalling and reinstalling opencv.
pip uninstall opencv-python
pip install opencv-python
After I updated opencv this error occured, in my case
pip list | grep opencv
showed:
opencv-contrib-python 4.5.3.56
opencv-python 4.5.5.62
I upgraded opencv-contrib-python
python -m pip install --upgrade opencv-contrib-python
and the error disappeared.
In case anyone else is having this issue on docker: I was trying to use version 4.3.0.38 and I couldn't find any pre-installed OpenCV on the docker image I was working with. Installing the package with conda install -c conda-forge opencv=4.3.0 instead of pip worked for me.
In my case, the following method was a solution.
pip list | findstr opencv
opencv-contrib-python 4.5.5.64
opencv-python 4.5.3.56
I installed opencv earlier than opencv contribution.
So, I decided to make their versions the same.
pip uninstall opencv-python==4.5.3.56
pip install opencv-python==4.5.5.64
The problem was gone.
Thanks.

cant import matplotlib due to pycairo 1.20

I have problems to import the matplotlibrary for my python3 script.
My system:
CentOS Linux 7 (Core)
Kernel 3.10.0-1062.9.1.el7.x86_64
Python 3.6.8
Minimal reproduction:
Setup:
python3 -m venv tester
source tester/bin/activate
pip install matplotlib
pip list
Gives:
Package Version
--------------- ---------
certifi 2020.6.20
cycler 0.10.0
kiwisolver 1.2.0
matplotlib 3.3.2
numpy 1.19.2
Pillow 8.0.1
pip 18.1
pyparsing 2.4.7
python-dateutil 2.8.1
setuptools 40.6.2
six 1.15.0
Now to actual reproduction:
python3
>>>from matplotlib import pyplot as plt
Gives:
Traceback (most recent call last):
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 15, in <module>
import cairo
ModuleNotFoundError: No module named 'cairo'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 21, in <module>
import cairocffi as cairo
ModuleNotFoundError: No module named 'cairocffi'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2336, in <module>
switch_backend(rcParams["backend"])
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 276, in switch_backend
class backend_mod(matplotlib.backend_bases._Backend):
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 277, in backend_mod
locals().update(vars(importlib.import_module(backend_name)))
File "/apps/shared/taifun/x86_64/apps/DATAPROCESSING/python/3.6.8/system/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 25, in <module>
"is installed") from err
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Ok, so we install pycairo:
pip install pycairo
Gives:
Collecting pycairo
Downloading <internal-package-server>/5a10cb7f9ae0d/pycairo-1.20.0.tar.gz (344kB)
100% |████████████████████████████████| 348kB 3.7MB/s
Installing build dependencies ... done
Installing collected packages: pycairo
Running setup.py install for pycairo ... done
Successfully installed pycairo-1.20.0
Lets check:
pip list
Seems ok:
Package Version
--------------- ---------
...
pycairo 1.20.0
...
New try:
python3
>>>from matplotlib import pyplot as plt
Nope, same error:
...
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Now, adapting the version to 1.11 works:
pip uninstall pycairo
pip install pycairo==1.11
python3
>>> from matplotlib import pyplot as plt
>>>
Hurray!
But why is pycairo 1.20 not working here? 1.11 -> 1.20 shouldn't be a breaking change and someone else should have notized this issue earlier. What might I be missing? Or should I actually open a ticket at matplotlib so they adapt their req. list?
Thanks in advance.
Ok, I managed to solve the issue. Several steps were necessary:
Switch from pycairo to cairocffi (as CForce99 suggested)
Update pip and setuptools (via entry to the gitlab-cy.yml), old version (40.x) had problems with cairocff's .tar.gz
Set the path to the certificate for my corporate's internal pypi mirror (export REQUEST_CA_BUNDLE)

Module six not found, although module six is installed

I cannot run jupyter lab as it complains about module six. Module six is already installed with conda. I even tried to install with pip too, but it says it is already installed and doesn't do anything. So, what to do here?
jupyter lab
Traceback (most recent call last):
File "c:\users\ilyas\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\ilyas\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\ilyas\Anaconda3\Scripts\jupyter-lab.EXE\__main__.py", line 5, in <module>
File "c:\users\ilyas\anaconda3\lib\site-packages\jupyterlab\labapp.py", line 11, in <module>
from jupyter_core.application import JupyterApp, base_aliases
File "c:\users\ilyas\anaconda3\lib\site-packages\jupyter_core\application.py", line 30, in <module>
from traitlets.config.application import Application, catch_config_error
File "c:\users\ilyas\anaconda3\lib\site-packages\traitlets\__init__.py", line 1, in <module>
from .traitlets import *
File "c:\users\ilyas\anaconda3\lib\site-packages\traitlets\traitlets.py", line 57, in <module>
import six
ModuleNotFoundError: No module named 'six'
I tried to remove with conda, and then re-install but that also did not work:
conda remove six
RemoveError: This operation will remove conda without replacing it with
another version of conda.
Install with pip:
pip install six
Requirement already satisfied: six in c:\users\ilyas\anaconda3\lib\site-packages (1.12.0)
python -m pip install six
Requirement already satisfied: six in c:\users\ilyas\anaconda3\lib\site-packages (1.12.0)
Environment:
Windows 10
python 3.7
jupyter-lab 1.0.0a3
six 1.12.0
you are installing six for Python 2, but trying to use it from Python 3.
install for Python 3 with:
python3 -m pip install six
Tried the following but still NOT solved:
I had to do this in the following error:
pip uninstall six
pip install six
Then I get the the ModuleNotFoundError: No module named 'jupyter_server' error.
So I install jupyter_server with conda, and now the jupyter lab is working.
conda install -c conda-forge jupyter_server
Even though the notebook is opening, I could not import packages. Checking the command prompt was showing the jupyterlab-manager was outdated. So, did the following:
jupyter labextension install #jupyter-widgets/jupyterlab-manager
Still, the notebook opens but cannot do anything with it.
few years late but I had the same problem. To add a little to what Corey was saying. I think you need to install it via Conda to use it in Conda (and hence Jupyter), i.e.
conda install six

Runtime Error when trying to launch Jupyter Notebook (Python)

I usually work with the Jupyter Notebook Interface when programming Python but recently I installed bioservices through pip (Bioservices) and when I tried to open the Jupyter Notebook I get the following RunTime error:
~$ jupyter notebook
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 7, in <module>
from notebook.notebookapp import main
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 60, in <module>
from .services.contents.manager import ContentsManager
File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/manager.py", line 16, in <module>
from nbformat import sign, validate, ValidationError
File "/usr/local/lib/python2.7/dist-packages/nbformat/__init__.py", line 33, in <module>
from .validator import validate, ValidationError
File "/usr/local/lib/python2.7/dist-packages/nbformat/validator.py", line 12, in <module>
from jsonschema import ValidationError
File "/usr/local/lib/python2.7/dist-packages/jsonschema/__init__.py", line 18, in <module>
from jsonschema.validators import (
File "/usr/local/lib/python2.7/dist-packages/jsonschema/validators.py", line 8, in <module>
import requests
File "/home/bioinfo/.local/lib/python2.7/site-packages/requests/__init__.py", line 74, in <module>
raise RuntimeError('Requests dependency \'chardet\' must be version >= 3.0.2, < 3.1.0!')
RuntimeError: Requests dependency 'chardet' must be version >= 3.0.2, < 3.1.0!
P.S: I uninstalled bioservices and it did not solve the error! Tried to reinstall chardet but it give the next output:
~$ pip install chardet==3.0.2
Collecting chardet==3.0.2
Using cached chardet-3.0.2-py2.py3-none-any.whl
Installing collected packages: chardet
Successfully installed chardet-2.3.0
This looks like a broken dependency. Have you tried installing the correct version of the chardet package, e.g.
pip install chardet==3.0.2
Of course here I'm assuming you have pip installed. Otherwise you're stuck with what your system ships. In that case, I would advise installing pip or any alternative way to control you python installation on a finer level.
Apparently you have a package named chardet required somewhere, but the version of this module is deprecated. Try to update chardet with pip upgrade chardet or uninstall and reinstall it.
$ pip uninstall chardet
$ pip install chardet
I have also same error. after trying all it doesn't work for me.
so I simply uninstall it:
pip uninstall jupyter
Then again install jupyter notebook
(it doesn't remove your installed library, simply uninstall jupyter) let's try

Categories