" No module named 'cv2' " but it is installed
Solution 1
1)Delete all your existing opencv installation
2) Reinstall it again in that way (python 3)
python -m pip install opencv-python
3) And Voila!
> import cv2
> sift = cv2.xfeatures2d.SIFT_create()
Solution 2
There is 2 possible problems about ModuleNotFoundError: No module named 'cv2'.
-
find the cv2.so file and move it into usr/local/lib/python3.6/site-packages
find / -name 'cv2.so'
possible output /usr/local/lib/python3.6/site-packages/cd /usr/local/lib/python3.6/site-packages/
cp cv2.so /usr/lib/python3.6/site-packages/
then quit the terminal and rerun it.
vi /etc/profile
edit the profile and addexport PYTHONPATH=/usr/local/lib/python3.6/site-packages:$PYTHONPATH
to the last line.
Solution 3
Probably you are loading python2 while the conda environment you used contains a python3 executable, or viceversa.
Which executable you are using to execute those lines? If it's something in a system directory, it doesn't have the same libraries you see with a conda list
.
You can prepend which
on linux to get the absolute path of an executable, e.g. which python
or which python3
.
See also the official conda documentation: https://conda.io/docs/user-guide/getting-started.html#managing-python
Personally I don't like conda, because it tends to mess up too many things, and I usually install everything with pip/virtualenvs or with a pipenv.
Related videos on Youtube
hajo
Updated on November 04, 2020Comments
-
hajo over 3 years
I have installed the whl file with include opencv + contribution because i want to use the SIFT-algorithm. I installed it with pip in my conda environment, so when i tipp in "conda list" it shows me "opencv-python 3.4.5+contrib " But when I try to run "ModuleNotFoundError: No module named 'cv2'". My Project is also using the correct environment
import cv2 sift = cv2.xfeatures2d.SIFT_create() ModuleNotFoundError: No module named 'cv2'
-
NemoMeMeliorEst over 5 yearshow did you install it? how do you run it?
-
-
NemoMeMeliorEst over 5 yearsFor python3 you would want to do; python3 -m pip install opencv-python
-
lattejiu over 2 yearsWorked for me as of August 23, 2021. To uninstall, I used "pip uninstall opencv-python".
-
Shurvir Mori over 2 years
python3 -m pip install opencv-python