在一個普通的非的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
建立?
我試過以下;所有均告失敗:
從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
從here我試圖向右前加上幾行:
sudo apt-get install python-software-properties sudo add-apt-repository python-opencv
python: - "2.7_with_system_site_packages"
更新
布爾汗·哈立德的回答沒有得到OpenCV的安裝,所以錯誤就走開了。然而,當我試圖找到使用import cv2
的包時,它仍然無法找到它,因爲Travis-CI構建機器被包裝在virtualenv中。所以我們不能在我們密封的構建環境之外訪問軟件包。
所以我從源代碼構建。 (參考文獻:here,here和here)
這裏是如何做到這一點的.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
這會在機器上安裝openCV,但它不好,因爲它與我的Travis-CI virtualenv隔離。查看我的問題中的更新。 –