Reputation: 31
I want to use opencv with GPU in order to speed things up. So I followed some tutorials on how to build opencv from source along with CUDA and cudnn.
I followed this tutorial without any problem, until the part where he
import cv2
in his terminal
My terminal showed that it can't find cv2 in the python environment.
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
I looked for the reason of this and found some clues. This post showed that he encountered the same problem as mine.
Starting from not having binding
folder in OpenCV.lsn after creating build folder with Cmake GUI
Also, I do not have python2 or python3 under To build session of my build/bin/release/opencv_version_win32.exe
, instead they are in unavailable session.
However, for hours of trying to find valid solution, I still can't find anything that can help me. So I hope there are someone who also faced this problem and can help me with this.
Upvotes: 2
Views: 1254
Reputation: 31
After some digging, I have found something very interesting. I have seen many suggestions through stackoverflow, github and opencv official website about missing python interpreter and related libraries.
So I just wanted to try it out and found out that my numpy is missing from the base python interpreter and show the below error when I tried to import numpy.
In order to check this, you cannot just import numpy from base environment. You have to go to
C:\{MY DIRECTORY}\anaconda3\python.exe
, click the file python.exe and try to import numpy
I have never noticed this before, since I always work within my virtual environment created by Anaconda so numpy is already there. (I do not know if this is always the case for everyone who encounters this problem and I do not know if this is the same solution for those who do not use anaconda)
All I have to do is finding the path to my Anaconda base library (in my case is)
C:\{MY DIRECTORY}\anaconda3\Library\bin
copy the path and add it to the system PATH.
After that, I redo the CMake buiding process again and everything works!!!
Hope this help some others who face the same problem.
Upvotes: 1