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]
I have this problem in my OS X El Capitan.
I followed the instructions mentioned in this tutorial. Didn't get a successful working install and had the above error of missing cv2.so file in the required folders mentioned and at the python
prompt.
Finally figured that using the virtual python setup was causing trouble. So uninstalled with
pip install virtualenv virtualenvwrapper
Then ran
brew link opencv
which threw errors.
And then followed below steps to resolve the issue.
First run
brew link opencv
If it gives an error, try for an automated diagnosis
brew doctor
brew doctor
gives a list of problems that could be leading to errors in installation process.
To fix problems in case of conflicting files, run to get a list of all actions which will be performed by overwrite without actually performing them.
To list all files that would be deleted:
brew link --overwrite --dry-run opencv
followed by this run which will execute the overwrite, assuming you feel that the actions performed by overwrite will take your system to a more stable state.
To force the link and overwrite all conflicting files:
brew link --overwrite opencv
This tutorial is a simpler alternative.
I install python-opencv
to solve my problem in Ubuntu 14.04
sh
sudo apt-get install python-opencv
Using raspbian on a rasberry pi I had the problem of the module not being found also. I had three versions of python (2.6, 2.7, and 3.2), be sure you are using python2.7. You can check this by running:
python --version
I found that for my case it was simply that I needed to install python-dev.
sudo apt-get install python-dev
I did Not have to remove and reinstall opencv, I tried my hardest to avoid that, knowing that it takes a few hours to complete the process.
After installing python-dev I went to the file I built the opencv into, for me it was " ~/opencv-2.4.9/release", and told it to make
sudo make
after this I was able to find the cv2.so file. searching for it with:
find / -name "cv2.so"
at this point I found a few files. next I ran just the python to see if it could find "import" them
python
>>> import cv2
no errors should come up.
>>> import numpy
I have heard that numpy was necessary for opencv to run. From there I believe you should be good to run your script, if no errors come about. I hope this helps.
The page that helped me is listed...
http://opencv-users.1802565.n2.nabble.com/I-can-t-find-cv-so-and-cv2-so-after-compiling-td6671937.html
In my case it was a problem with cmake
:
sudo apt install software-properties-common
sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt update
If cmake
is not yet installed:
sudo apt install cmake
If cmake
is already installed:
sudo apt upgrade
For more information, see this link.
I had a similar problem when I manually configured using CMAKE on OSX El Capitan. I had given this additional option:
PYTHON2_PACKAGES_PATH='lib/python2.7/site-packages'
which stopped the cv2.so in that package from getting installed. It seems to install properly in my build folder after I removed it:
PYTHON2_EXECUTABLE='/usr/bin/python2.7'
PYTHON2_INCLUDE_DIR='/usr/include/python2.7'
PYTHON2_LIBRARY='/usr/lib/libpython2.7.dylib' # TODO - Fix for linux
PYTHON2_NUMPY_INCLUDE_DIRS='/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include' # Todo - Fix for linux
cd $OPENCV_DIR
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$OPENCV_INSTALL_PATH \
-D WITH_CUDA=OFF \
-D BUILD_opencv_python2:BOOL=ON \
-D PYTHON2_EXECUTABLE=$PYTHON2_EXECUTABLE \
-D PYTHON2_INCLUDE_DIR=$PYTHON2_INCLUDE_DIR \
-D PYTHON2_LIBRARY=$PYTHON2_LIBRARY \
-D PYTHON2_NUMPY_INCLUDE_DIRS=$PYTHON2_NUMPY_INCLUDE_DIRS \
-D INSTALL_PYTHON_EXAMPLES:BOOL=ON \
..
make -j8
make install
I came across similar problem. After digging into this a little more I came across a post where it was mentioned that python-numpy
package was required. So, I uninstalled the opencv by running the following command in build folder(in your case release folder):
dpkg -r build
Then I removed all the opencv files. I installed python-numpy
and python-dev
with this command:
sudo apt-get install python-dev python-numpy
Then, after re-running the installation script, import cv2
command in python console doesn't give me any error and is properly imported.