python-2.7 - 特拉维斯 CI : "Unable to locate package python-opencv" Python 2. 7

标签 python-2.7 opencv

在普通的非 virtualenv Ubuntu 机器上我可以运行:

sudo apt-get install python-opencv

然后我可以从 Python 2.7 运行 import cv2。成功!

但是当我尝试在我的 .travis.yml 文件中做同样的事情进行自动化测试时,我得到了错误:

E: Unable to locate package python-opencv

如何让 apt-get 在我的 Travis-CI 构建中找到 python-opencv

我尝试了以下方法;都失败了:

  1. 来自 https://askubuntu.com/questions/339217/ ,我尝试将这些行附加到 /etc/apt/sources.list:

    echo "deb http://de.archive.ubuntu.com/ubuntu precise main restricted universe" | sudo tee -a /etc/apt/sources.list
    echo "deb-src http://de.archive.ubuntu.com/ubuntu precise restricted main multiverse universe" | sudo tee -a /etc/apt/sources.list
    echo "deb http://de.archive.ubuntu.com/ubuntu precise-updates main restricted universe" | sudo tee -a /etc/apt/sources.list
    echo "deb-src http://de.archive.ubuntu.com/ubuntu precise-updates restricted main multiverse universe" | sudo tee -a /etc/apt/sources.list
    
  2. 来自 here我之前尝试添加这些行:

    sudo apt-get install python-software-properties
    sudo add-apt-repository python-opencv
    
  3. 正在关注 this , 使用来自 here 的更新方法,我尝试使用它而不是 2.7:

python : - “2.7_with_system_site_packages”

(我的完整 .travis.yml file is here .)

更新

Burhan Khalid 的回答确实安装了 OpenCV,因此错误消失了。然而,当我尝试使用 import cv2 查找包时,它仍然找不到它,因为 Travis-CI 构建机器被包装在一个 virtualenv 中。因此,我们无法访问密封构建环境之外的包。

所以我从源代码构建。 (引用:hereherehere)

这是在 .travis.yml 文件中的做法:

env:
  global:
    # Dependencies
    - DEPS_DIR="`readlink -f $TRAVIS_BUILD_DIR/..`"
    - OPENCV_BUILD_DIR=$DEPS_DIR/opencv/build

然后,在 before_install 部分:

  - travis_retry git clone --depth 1 https://github.com/Itseez/opencv.git $DEPS_DIR/opencv
  - mkdir $OPENCV_BUILD_DIR && cd $OPENCV_BUILD_DIR

  - |
      if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then 
        cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -DPYTHON_EXECUTABLE=$(which python) -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
      else
        cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") -DPYTHON_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
      fi
  - make -j4
  - sudo make install

  - echo "/usr/local/lib" | sudo tee -a /etc/ld.so.conf.d/opencv.conf
  - sudo ldconfig
  - echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" | sudo tee -a /etc/bash.bashrc
  - echo "export PKG_CONFIG_PATH" | sudo tee -a /etc/bash.bashrc
  - export PYTHONPATH=$OPENCV_BUILD_DIR/lib/python3.3/site-packages:$PYTHONPATH 

最佳答案

之后:

sudo add-apt-repository python-opencv

你需要

sudo apt-get update

以便正确更新新的仓库信息;在您可以从该存储库添加包之前。

关于python-2.7 - 特拉维斯 CI : "Unable to locate package python-opencv" Python 2. 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34523651/

相关文章:

c++ - 在 Visual C++ 2010 Express 中安装 OpenCV 2.4.3

c++ - flann索引使用LshIndexParams需要什么类型的数据?

python - Opencv全向标定校正

Python 2.7 读取模板并返回带有替换的新文件

python - PyQt : switch windows/layouts created by Qt Designer

python - 化圆为方。已解决 : squircle package

c++ - OpenCV 架构 x86_64 的 undefined symbol : lineDescriptor

macos - 让 pygame 在 Macos 上显示除空白屏幕之外的任何内容时出现问题

python - 将键添加到字典列表中

python - 1 函数 prim 的算法 python