No module named cv - python

I'm trying to run this script:
https://github.com/openalpr/train-detector/blob/master/crop_plates.py
I've never dealt with python before. First of all I had some syntax errors in the print lines. They were lacking parentheses...but I'm not sure if I get this error because of the Python version I installed or this was indeed a syntax error. After fixing the syntax error I'm receiving the following error:
C:\>py crop_plates.py
Traceback (most recent call last):
File "crop_plates.py", line 7, in <module>
import cv2, cv
ImportError: No module named cv
I did the following:
Installed Python 2.7.5 32 bits.
Installed numpy 1.9.1 32 bits (also tried different versions)
Installed matplotlib 1.3.0.
Installed OpenCv
Copied cv2.pyd from
C:\Users\Me\Downloads\opencv\build\python\2.7\x86
to
C:\Python27\Lib\site-packages
But I can't find anywhere the cv.pyd file that I'm missing.
I found references to this guide for installing Opencv but it's not working
http://opencv.willowgarage.com/documentation/python/
Thank you very much,
Edit: I'm running Python in Windows 7.

For ImportError: No module named cv, try installing opencv-python module using below command:
pip install opencv-python

cv2.cv doesn't exists in OpenCV 3.0. Use simply cv2
Also, the attribute is no more CV_HOUGH_GRADIENT but HOUGH_GRADIENT
So what you looking for is probably:
cv2.HOUGH_GRADIENT

OK , I searched for a while and find the following :
First: you may write: import cv2.cv as cv to solve your proplem
cv and cv2 are both interface for python , and now , the newest "cv2" is the most used one , but clearly some libraries still use cv and others (like yours) use mix of the two,What is different between all these OpenCV Python interfaces?

It seems this code is using a old version of OpenCV. Unfortunately there is no mention of the exact version they used in their repo.
As the code is at least 2 years old, I would install opencv version 2.4.
pip install opencv-python==2.4

Related

ModuleNotFoundError, even after pip install

I have recently bought a new laptop and was viewing some python projects of mine which I made on my pc. For one of them I use the python-bitvavo-api library which I installed using pip3 install python-bitvavo-api. The version I installed is 1.2.2 which is the latest on their website.
Now when I try to import it using this code: from python_bitvavo_api.bitvavo import Bitvavo, I get the following error:
Traceback (most recent call last):
File "C:\Users\indig\OneDrive\Documenten\Python Projects\Personal\Cryptone\Cryptone.py", line 6, in <module>
from python_bitvavo_api.bitvavo import Bitvavo
ModuleNotFoundError: No module named 'python_bitvavo_api'
I read online that it may occur when using multiple python versions, Im only using 1 and thats python 3.7
Btw. I have the same error with the Pillow module, so it might be a setting in visual studio that I dont know of. Anyway, someone please help. If you need more details please ask.
How are you running it? From the terminal or from VS?
You can also check the installed libraries running the command pip list

Import Error when using VSCode with conda interpreter but not when importing in Conda

I'm trying to run a Python program in VSCode and it always stops in the first line
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
The error it gives me is pretty big, I'll paste it at the end.
However, when when I open python in my conda terminal, I can import with no issues at all. Since I'm using the conda interpreter in VSCode, I don't understand what the issue is.
My Python version is 3.7.6, numpy 1.19.1, scipy 1.5.2, sklearn 0.23.2 and am working with Windows 10. I have already tried what the webpage mentioned suggested. And on the bottom left of VSCode it says that the interpreter is Python 3.7.6 64-bit ('base':conda).
Just tried, and I can't import numpy either, but can in conda with no problems. The python versions are the same. EDIT: The error message here asks me to be sure that the Numpy version is 1.18.1, instead of 1.19.1.
Exception has occurred: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python3.7 from "C:\Users\jdion\anaconda3\python.exe"
The NumPy version is: "1.19.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
File "C:\Users\jdion\OneDrive\Ambiente de Trabalho\Tese\Code\The Sea Exploration Problem _aux.py", line 13, in
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
I uninstalled both conda and all my Python versions and when I reinstalled Python 3.7.9 and selected it as the interpreter in VSCode there were no more issues. I think the problem was having too many Python versions, anaconda, pip, and I was probably installing and removing things in the wrong places.

import error even after installing the utils in python3.6

I am trying to run an image recognition code. Even after installing 'utils' I am still getting error that module not found. What should I change?
Check if your python version is compatible. According to docs it's up to python 3.4 and you seem to be using 3.6. Source - https://pypi.org/project/python3-utils/#data

cv2.dnn' has no attribute 'readNet' using python 3.6 and opencv3.4.1

I have downloaded the source code of Opencv3.4.1 from github and I have built it from the source using CMake. Everything went very well and it's installed!
But When I run this script: https://github.com/opencv/opencv/blob/master/samples/dnn/object_detection.py
I get the following error:
Traceback (most recent call last):
File "object_detection.py", line 52, in <module>
net = cv.dnn.readNet(args.model, args.config, args.framework)
AttributeError: module 'cv2.dnn' has no attribute 'readNet'
System information (version)
OpenCV => 3.4.1
Operating System / Platform => Windows 64 Bit
Python =>3.6
When I run print(cv.__version__) I get 3.4.1 But I can't find the that function or any other new features in the 3.4.1 version!
I have built from the source on Ubuntu 16.04 and on Windows 10. But still no luck! the source is downloaded from Github https://github.com/opencv/opencv/archive/3.4.1.zip
Does anyone has any tips?
Thanks to api55 for his suggestion!
I could solve the problem by downloading the source code from the current master branche of opencv https://github.com/opencv/opencv
change readNet function with readNetFromDarknet
nb : if you have the failure no attribute named RedNetFromDarknet , this is because this function is implemented in opencv_3.3.1 and greater versions.
for my case it have the same problem with opencv_3.3.0 and i noticed that this function is not implemented in this version. That's why you should check if the version you are using contain this function.
I got this problem too because I had an old version of Opencv (3.x). So, I tried pip uninstall opencv-python then pip install opencv-python and now I have the newest one (4.x) and cv2.dnn.readNet is now recognized.

Trying to make Open CV python work on Anaconda Jupyter

Installing OpenCV from prebuilt binaries
Below Python packages are to be downloaded and installed to their default locations.
Python-2.7.x.
Numpy.
Matplotlib (Matplotlib is optional, but recommended since we use it a lot in our tutorials).
Install all packages into their default locations. Python will be installed to C:/Python27/.
After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.
Download latest OpenCV release from sourceforge site and double-click to extract it.
Goto opencv/build/python/2.7 folder.
Copy cv2.pyd to C:/Python27/lib/site-packages.
Open Python IDLE and type following codes in Python terminal.
import cv2
print cv2.version If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python
successfully.
import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <modul
ImportError: No module named cv2
I am trying to get tesseract and opencv up and running for past 2 days.I had uninstall python 3 and almost everything related to it as most of the modules ran in python 2.7 .Still after reverting back python 2.7 and reinstalling everything still its showing No module named cv2.Am at my wits end .Please help me

Categories

Resources