import cv2 error could not do this command [duplicate] - python

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.

Related

cv2 not work after install mediapipe library

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.

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.

Problem with CV2 : numpy.core.multiarray failed to import

Tried to solve it with :
pip install -U numpy
but it still does not work.
That is what the console shows to me when I try to run the application :
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "/Users/Rubio/Desktop/logistic-regression/train.py", line 8, in <module>
import cv2
File "/Library/Python/2.7/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
Uninstall & Install Numpy
conda uninstall numpy
conda install -c conda-forge numpy
it works
I had a file named numbers.py in the same folder.
Removing this file solved the issue for me.
Very strange, but worked.
Two solutions. I faced this problem with ai2thor environment.
Just add import numpy.core.multiarray before the import cv2 statement
Update number: pip install -U --no-cache-dir numpy==1.19.3
Reinstall OpenCV:
conda install -c anaconda opencv (for anaconda users)
I discovered that my problem was that I had two versions of numpy installed, I uninstall one of them and it worked normal.
I faced this error with Tello Drone "DJITelloPy" and this solution from Soroush Karimi saved the day.
pip uninstall numpy
pip install numpy==1.19.3

Tensorflow error : DLL load failed: The specified procedure could not be found

I tried to install tensorflow cpu using pip in my windows8.1 64bit python3.6.0
using pip install tensorflow
but it gives me this error:
Traceback (most recent call last): File "C:\Users\Laitooo
San\Desktop\tf.py", line 1, in <module>
import tensorflow as tf File "C:\Users\Laitooo San\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py",
line 24, in <module>
from tensorflow.python import * File "C:\Users\Laitooo San\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py",
line 52, in <module>
from tensorflow.core.framework.graph_pb2 import * File "C:\Users\Laitooo
San\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\core\framework\graph_pb2.py",
line 6, in <module>
from google.protobuf import descriptor as _descriptor File "C:\Users\Laitooo
San\AppData\Local\Programs\Python\Python36\lib\site-packages\google\protobuf\descriptor.py",
line 47, in <module>
from google.protobuf.pyext import _message ImportError: DLL load failed: The specified procedure could not be found.
I downloaded python36.dll and made sure all other .dll is there and install Microsoft visual c++ 2015
I also uninstalled tensorflow and installed another version several times but without any result.
I had this error as well, and was able to resolve it by downgrading protobuf from 3.6.1 to 3.6.0:
pip install protobuf==3.6.0
windows 10
python 3.6
Cuda 9.0
cudnn-9.0-windows10-x64-v7.6.3.30
tensorflow-gpu == 1.12.0
keras == 2.2.4
problem was:
ImportError: DLL load failed: The specified procedure could not be
found.
solved with:
pip install protobuf==3.6.0
There is a similar issue on Github:
Tensorflow issue
Problem should be resolved if you install the wheel file provided in one of the answers. You can find the wheel file here.
Wheel file
You can install the wheel file with pip. First change the current directory to install location. Then,
pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl
All official tensorflow binaries since 1.6 were made with AVX, rendering older CPUs unsupported.
In order to install recent tensorflow versions on an older CPU you can simply install tensorflow from a non-avx built wheel ( you can find some here)
pip install <path to the downloaded .whl file>
its the problem with python=3.6.0
Upgrade to any higher versions of python 3.6
Updating from python 3.6.0 to python 3.6.4 fixed this issue for me.
I got this (unhelpful) error after installing on python 3.7. Turns out I had not installed cuDNN, the neural network package. After that, it runs without issue.
I had the same problem.
I made it work by uninstalling scipy and then reinstalling.
First uninstall seaborn.
pip uninstall seaborn
then uninstall scipy.
pip uninstall scipy.
After that install both scipy and seaborn.
pip install scipy,
pip install seaborn
I hope it helps

Python multi-version error _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE

I have an error when running app with python3.5
Traceback (most recent call last):
File "/usr/local/bin/face_recognition", line 7, in <module>
from face_recognition.cli import main
File "/usr/local/lib/python3.5/site-packages/face_recognition/__init__.py", line 7, in <module>
from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces, face_distance
File "/usr/local/lib/python3.5/site-packages/face_recognition/api.py", line 4, in <module>
import dlib
File "/usr/local/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: /usr/local/lib/python3.5/site-packages/dlib/dlib.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
I can see that libboost is the problem, I compiled it with appropriate version of python and set python root as well but still have an error. What did I miss?
I also meet this kind of problem. On my Mac, I have installed a version of boost 1.58 from source code.
When I try to install dlib by following command:
brew install cmake
brew install boost
brew install boost-python --with-python3
sudo pip3 install numpy
sudo pip3 install scipy
sudo pip3 install scikit-image
sudo pip3 install dlib
I think dlib use the wrong version of boost on my Mac.
Here is my solution:
try to delete boost using brew uninstall, and delete all related boost include and lib files from /usr/local/include & /usr/local/lib.
reinstall above brew & pip3 commands to reinstall all related libraries.
After this two steps, my Mac now can use dlib under Python3 correctly.

Categories