I have installed the opencv-python lib (Here the installed lib) but when I use a function (cv2.VideoCapture(0)) of the imported cv2 (import cv2) module, pycharm raised the error:
AttributeError: module 'cv2' has no attribute 'VideoCapture'
While in the python basic IDE (IDLE) it works great.
I saw the solution for pycharm was to import cv2 this way:
from cv2 import cv2
But I don't understand why I should import it like that in pycharm
Related
import cv2
ModuleNotFoundError: No module named 'cv2'
although it already installed but run in cmd only
not working in any IDE like Vs or spyder or Jupyter
i wanna to make IDE import OpenCv
try:
import opencv-python
except:
subprocess.check_call([sys.executable, "-m", "pip", "install", 'opencv-python'])
Alternatively, open a console in your IDE and execute the following:
pip install opencv-python
Your IDE probably uses a different python instance to the one your console uses
I am using Python 3.6.8 on Windows 10
I installed tensorflow, keras, and utils using pip.
pip install tensorflow and it installs the version 2.0.0
pip install keras and it installs the version 2.3.1
pip install utils but it does not show what version I have installed.
This is my header:
from keras.preprocessing import image
from PIL import Image
from keras.models import model_from_json, load_model
import numpy as np
import cv2
from datetime import datetime
import os
import random
import string
from utils.datasets import get_labels
from utils.inference import apply_offsets
from utils.inference import load_detection_model
from utils.preprocessor import preprocess_input
This is my error:
from utils.datasets import get_labels
ModuleNotFoundError: No module named 'utils.datasets'
Why am I getting this error? And how to fix it? BTW The code was written by a previous programmer and I need to modify it. But I can't even run it. not so good in python tho. i'm just getting started to it.
All my google search are all purple but I can't seem to find any solutions.
EDIT
The suggested answer (ImportError: No module named datasets) does not satisfy my needs. I am having trouble on utils module. because when I comment out the line from utils.datasets import get_labels
The error is on the next line:
ModuleNotFoundError: No module named 'utils.inference'
The utils model what the code your provided want to import is the part of the oarriaga/face_classification project.
The pip installed utils modul is quite different package, so you should not have installed via pip. Your code try to import moduls from this package, but it obviously has no such moduls. That is why the error messages.
So what you have to do is pip uninstall utils and then if your project directory structure is complete, the above code will import the face_classification package's moduls.
I have got a python code from open source community where it imports cv as well as cv2. After installing opencv using conda 'import cv2' resolved. But still I have issue with 'import cv', where it shows 'ImportError: No module named cv'.
Few other things I have tried:
1. sudo apt-get install python-opencv
2. pip install opencv
3. import cv2.cv as cv
Can any one help me how to resolve "No module named cv"?
Note that I am using python version 2.7.13
In my code I am using as below:
import cv2
import cv
And getting the following error:
import cv
ImportError: No module named cv
The cv module was removed actually before OpenCV 3.0. Regardless, most things accessible through the cv module are still accessible. The cv.CV_CAP_PROP_FPS setting is now cv2.CAP_PROP_FPS.
Basically, the constants given by CV_XXX_XXX used to be accessible through the old cv module via cv2.cv.CV_XXX_XXX but now it's not necessary---just remove the prepended CV_ and use the cv2 module.
I am new to Python and I have installed OpenCV library which ends with cv2.so file installed in /usr/local/lib/python2.7/site-packages. When I try to import this library in my code with import cv2, I get
ImportError: No module named cv2
How can I manage that
Here is what I have done
import cv2
import sys
sys.path.append('/usr/include/opencv')
im = cv2.imread("im1.png")
print type(im)
Then terminal gives me
File "m7.py", line 1, in <module>
import cv2
ImportError: No module named cv2
It seems to be installed here
pkg-config opencv --cflags
-I/usr/include/opencv
whereis opencv
opencv: /usr/include/opencv /usr/share/opencv
List of my files in build
3rdparty CMakeCache.txt cmake_uninstall.cmake cvconfig.h include Makefile OpenCVConfig.cmake unix-install
apps CMakeFiles CPackConfig.cmake data junk modules OpenCVConfig-version.cmake version_string.tmp
bin cmake_install.cmake CPackSourceConfig.cmake doc lib opencv2 OpenCVModules.cmake
try adding the path before you try to import the cv modules.
import sys
sys.path.append('/usr/include/opencv')
import cv2
Regards