Shalin Shah Shalin Shah - 3 months ago 39
Python Question

Installing OpenCV/python on Amazon Linux (apache)?

I am trying to use OpenCV on a python web application I created on an Amazon EC2 Micro instance running apache.

I've got everything configured and working, except OpenCV isn't installing. This is the output I got from the Apache Error Log.

[Thu Aug 04 18:31:54 2016] [error] [client] import cv2
[Thu Aug 04 18:31:54 2016] [error] [client] ImportError: No module named cv2

Here is what I've tried:

I've installed pip and tried running
pip install pyopencv

That doesn't work and gives me errors.

I've also tried manually installing it by following this: How to install OpenCV on Amazon Linux?

and this:

and this:

Even after installation, the file is nowhere to be be found. I tried to search for it using
sudo find / -name ""
but nothing came up.

I do, however, have the following
files installed:


Also, when running the cmake command, this is the output I'm getting:

-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.10)
-- Libraries: NO
-- numpy: NO (Python wrappers can not be generated)
-- packages path: lib/python2.7/dist-packages

Any help is appreciated.


tested and working on amzn-ami-hvm-2016.03.1.x86_64-gp2

sudo yum install git cmake gcc-c++ numpy python-devel 
sudo pip install --upgrade pip
sudo ln -rs /usr/local/bin/pip /usr/bin/
sudo pip install numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl 
git clone
cd opencv
git checkout 3.1.0
mkdir build
cd build
cmake .. -DBUILD_opencv_python2=ON
make -j4
sudo make install
echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/:/usr/local/lib/python2.7/dist-packages/'>>~/.bashrc;. ~/.bashrc
python -c 'import cv2; print "cv2 imported"'

most importantly after cmake step. you should see this in the output.

--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.10)
--     Libraries:                   /usr/lib64/ (ver 2.7.10)
--     numpy:                       /usr/local/lib64/python2.7/site-packages/numpy/core/include (ver 1.11.1)
--     packages path:               lib/python2.7/dist-packages

now if it is not showing up, you need to completely remove build folder and rerun cmake again after correctly installing numpy, just rerunning cmake inside your already existing build folder will not work.