2015-12-30 362 views
1

在一個普通的非的virtualenv Ubuntu的機器,我可以運行:特拉維斯CI: 「無法找到包python-OpenCV的」 巨蟒2.7

sudo apt-get install python-opencv 

然後從Python 2.7版,我可以運行import cv2。成功!

但是,當我嘗試做同樣的事情在我.travis.yml文件進行自動測試,我得到的錯誤:

E: Unable to locate package python-opencv

我怎樣才能apt-get的在我的特拉維斯-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

更新

布爾汗·哈立德的回答沒有得到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 

回答

1

後:

sudo add-apt-repository python-opencv 

You nee d

sudo apt-get update 

因此,新的存儲庫信息被正確更新;然後才能從該存儲庫添加軟件包。

+0

這會在機器上安裝openCV,但它不好,因爲它與我的Travis-CI virtualenv隔離。查看我的問題中的更新。 –