Today I installed opencv 2.4.4 to Ubuntu 12.10
But import cv2 not works.
root@-:~# python Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named cv2 >>>
As I understand cv2.so missed, so python don't see where opencv
root@-:~# find / -name "cv.py" /root/opencv-2.4.4/modules/python/src2/cv.py root@-:~# find / -name "cv2.so" root@-:~#
My setup steps look like
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.4/OpenCV-2.4.4a.tar.bz2 tar -xjf OpenCV-2.4.4a.tar.bz2 cd opencv-2.4.4 mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON .. make && make install echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf ldconfig echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc
Where is cv2.so ? And why it was missed ?
The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.
cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.
cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python".
The file cv2.so is stored in /usr/local/lib/python2. 7/site-packages/... There are also folders in /usr/local/lib called python3. 2 and python2.
How to install opencv(cv2) with python bindings in Linux - Ubuntu/Fedora
Install gcc, g++/gcc-c++, cmake (apt-get or yum, in case of yum use gcc-c++)
apt-get install gcc, g++, cmake
Downlaod latest opencv from openCV's website
Untar it with
tar -xvf opencv-*
Inside the untarred folder make a new folder called release
mkdir release cd release
(or any folder name) and run this command in it
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
the ..
will pull files from the parents folder and will get the system ready for installation on your platform.
in the release folder run
make
After about 2-3 mins of make processing when its finished run
sudo make install
Export python path
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
That's it, now go to python and try
>>> import cv2
you should not get any error message.
Tested on python 2.7, should be virtually similar to python 3.x.
I install python-opencv
to solve my problem in Ubuntu 14.04 sh sudo apt-get install python-opencv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With