Reputation: 1871
I tried to build opencv 3 with python support (with cuda, too) for Ubuntu 14.04 using CMake-gui.
The compilation seems to work fine until from a Python console:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
I tried both with python3 enabled or disabled without change. The cmakeCache.txt is here.
Any idea to fix the problem?
Upvotes: 3
Views: 3696
Reputation: 321
I had the same problem since yesterday, and I solved it as follows:
Now you can make/compile the usual way. The cv2.so file will be created in build/lib/ directory. With make install it will be installed for Python 2.
If it still does not work maybe the problem is somewhere else. After step 8, the cmake output must include the lines (actual paths might be different in your case):
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.6)
Libraries: /usr/lib/i386-linux-gnu/libpython2.7.so (ver 2.7.6)
numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
packages path: lib/python2.7/dist-packages
In no case there can be a line saying NO, like:
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.6)
Libraries: NO
numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
packages path: lib/python2.7/dist-packages
Hope this helps.
Upvotes: 4
Reputation: 346
If it compiles fine, then the probem isn't with cmake or the way your build options are set. The problem looks like it isn't with python2 or 3 either, but the way you have OpenCV installed. After you compile OpenCV you have to move your opencv python modules to /usr/local/lib or python won't be able to see them.
Upvotes: 1