2016-08-04 133 views
2

我想在運行apache的Amazon EC2 Micro實例上創建的python web應用程序上使用OpenCV。在Amazon Linux(apache)上安裝OpenCV/python?

我已經配置好了所有配置和工作,除了OpenCV沒有安裝。這是我從Apache錯誤日誌中獲得的輸出。

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

這裏是我試過:

我已經安裝了點子和嘗試運行pip install pyopencv

這並不工作,給我的錯誤。 How to install OpenCV on Amazon Linux?

這:http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.html?highlight=download#installing-opencv-python-from-pre-built-binaries

這:http://techieroop.com/install-opencv-in-centos/

即使安裝後,cv2.so文件無處可

我也試過手動按照此安裝它被發現。我試圖用sudo find/-name "cv2.so"搜索它,但沒有出現。

我這樣做,不過,已經安裝了以下.so文件:

/usr/local/lib/libopencv_photo.so 
/usr/local/lib/libopencv_stitching.so 
/usr/local/lib/libopencv_flann.so 
/usr/local/lib/libopencv_imgcodecs.so 
/usr/local/lib/libopencv_videostab.so 
/usr/local/lib/libopencv_ml.so 
/usr/local/lib/libopencv_objdetect.so 
/usr/local/lib/libopencv_imgproc.so 
/usr/local/lib/libopencv_superres.so 
/usr/local/lib/libopencv_core.so 
/usr/local/lib/libopencv_video.so 
/usr/local/lib/libopencv_highgui.so 
/usr/local/lib/libopencv_features2d.so 
/usr/local/lib/libopencv_shape.so 
/usr/local/lib/libopencv_videoio.so 
/usr/local/lib/libopencv_calib3d.so 

而且,在運行cmake的命令時,這是我得到的輸出:

-- 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 

任何幫助讚賞。

+0

你複製cv2.so到站點包你的Python分佈下(如/usr/local/lib/python2.7/site-packages) ? – bblincoe

+0

@bblincoe其中是cv2.so文件?在我的/usr/local/lib/python2.6/中,我沒有任何cv2.so文件,但是我有用於點的文件。在我的/usr/local/lib/python2.7/我只有一個自述文件 –

+0

看看這個線程:http://stackoverflow.com/questions/15790501/why-cv2-so-missing-after-opencv-安裝 – bblincoe

回答

12

測試和cmake的步驟之後,在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/ 
wget https://pypi.python.org/packages/18/eb/707897ab7c8ad15d0f3c53e971ed8dfb64897ece8d19c64c388f44895572/numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl 
sudo pip install numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl 
git clone https://github.com/Itseez/opencv.git 
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"' 

工作最重要的。你應該在輸出中看到這個。

-- Python 2: 
--  Interpreter:     /usr/bin/python2.7 (ver 2.7.10) 
--  Libraries:     /usr/lib64/libpython2.7.so (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 

現在如果它沒有顯示出來,你需要完全正確後安裝numpy的,只是重新運行您現有的build文件夾不會在裏面工作的cmake再次刪除build文件夾,然後重新運行cmake的。

+0

進行搜索。我運行了'cmake'命令,並意識到'numpy'沒有正確安裝。所以我做了'sudo yum卸載numpy'。然後我試着安裝'numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl',但是我得到了'numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl不是這個平臺上支持的輪子' –

+0

我已經也更新了我的問題與運行'cmake' –

+0

hmm ..時得到的輸出結果。這裏列出的whl https://pypi.python.org/pypi/numpy。有4個用於Linux。 –

1

我想下面的命令和它的工作:

cmake -D PYTHON2_LIBRARIES=/home/ubuntu/anaconda2/lib/libpython2.7.so.1.0 \ 
-D PYTHON2_INCLUDE_DIR=/home/ubuntu/anaconda2/include/python2.7/ \ 
-D PYTHON2_EXECUTABLE=/home/ubuntu/anaconda2/bin/python \ 
-D HAVE_opencv_python2=ON .. 
相關問題