我正试图在运行apache的AmazonEC2Micro实例上创建的python web应用程序上使用OpenCV。
除了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并尝试运行pip install pyopencv
这不起作用,给我带来了错误。
我还尝试过手动安装它,方法是:如何在AmazonLinux上安装OpenCV?
并且这个: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
并且这个: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
感谢您的帮助。
在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"'
最重要的是在cmake步骤之后。您应该在输出中看到这一点。
-- 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后再次运行cmake,仅仅在你已经存在的构建文件夹中重新运行cmake是行不通的。
首先用python的更新版本为python创建一个虚拟环境,因为默认情况下会在上面安装python2.7。从以下链接获取帮助:-
https://aws.amazon.com/premiumsupport/knowledge-center/python-boto3-virtualenv/
然后cd进入venv文件夹并执行命令:-
$pip安装opencv-python
现在,通过激活虚拟环境来运行任何包含opencv的脚本。
$source/home/ec2 user/venv/python34/bin/activate
完成!!!
我尝试了下面的命令,它成功了:
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 ..