You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Raspbian Jessie中正确安装cv2?python3-opencv安装报错求助

Hey there, let's sort out this OpenCV installation problem you're facing on Raspbian Jessie with Python 3.4.2. The errors you're getting happen because the package names you tried aren't quite right, and Raspbian Jessie's default repositories don't include a pre-built Python 3 OpenCV package. Here are the most reliable ways to get cv2 installed:

Method 1: Try updating your package sources first

Sometimes the missing package issue is just because your repo list is outdated or missing the right sources. Give this a shot:

  • Update your package index and upgrade existing packages:
    sudo apt-get update && sudo apt-get upgrade -y
    
  • Open your sources list file to add a more complete repo:
    sudo nano /etc/apt/sources.list
    
  • Make sure the file includes this line (if it's missing, add it at the end):
    deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
    
  • Save and exit the editor (press Ctrl+O, hit Enter, then Ctrl+X), then update again:
    sudo apt-get update
    
  • Now try installing the correct package:
    sudo apt-get install python3-opencv
    

If this still fails (which is common for older Jessie builds), move on to the more reliable source compilation method below.

Method 2: Compile OpenCV from source (most reliable for old systems)

Since Raspbian Jessie is pretty outdated, pre-built packages are hard to come by. Compiling from source ensures compatibility with your Python 3.4.2 environment. It takes a bit of time, but it works every time:

  1. Install all required dependencies
    Run this command to grab every tool and library OpenCV needs:

    sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk2.0-dev libgtk-3-dev libatlas-base-dev gfortran python3-dev python3-pip
    
  2. Install NumPy (required for OpenCV)

    pip3 install numpy
    
  3. Download compatible OpenCV source code
    We'll use OpenCV 3.4.16, the last stable 3.x release that works with Python 3.4:

    cd ~
    git clone https://github.com/opencv/opencv.git
    cd opencv
    git checkout 3.4.16
    cd ..
    git clone https://github.com/opencv/opencv_contrib.git
    cd opencv_contrib
    git checkout 3.4.16
    cd ..
    
  4. Configure the build environment
    Create a build directory and set up compile options tailored to your system:

    cd opencv
    mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D INSTALL_PYTHON_EXAMPLES=ON \
          -D INSTALL_C_EXAMPLES=OFF \
          -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
          -D PYTHON_EXECUTABLE=/usr/bin/python3 \
          -D BUILD_EXAMPLES=ON ..
    
  5. Start compiling
    This will take 1-2 hours on a typical Raspberry Pi. Use -j2 to use 2 CPU cores (adjust to -j4 if you have a Pi 3/4 with more cores):

    make -j2
    
  6. Install the compiled files

    sudo make install
    sudo ldconfig
    
  7. Verify the installation
    Open a Python 3 shell and test importing cv2:

    import cv2
    print(cv2.__version__)
    

    If you see 3.4.16 printed out, you're good to go!

Quick note on your original errors: The pip3 install python3-opencv command was incorrect—PyPI's package name for OpenCV is opencv-python, but even that won't work for Python 3.4 on Jessie since newer PyPI packages drop support for older Python versions. Compiling from source is the safest bet here.

内容的提问来源于stack exchange,提问作者Nishajith .A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:25:18