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

Python3.6.4缩进错误及人脸识别代码运行异常求助

Fixing the "unindent does not match any outer indentation level" Error in Your Face Recognition Code

Hey there, that unindent does not match any outer indentation level error is super common in Python—it’s all about messed-up indentation (Python takes this very seriously!). Let’s break down what’s wrong with your code and fix it step by step:

Key Issues in Your Original Code

  • Malformed import statements: You tried to cram multiple import commands onto a single line, which isn’t valid Python syntax.
  • Incorrect indentation: The code inside your getImagesWithID function wasn’t properly indented—Python requires consistent indentation (stick with 4 spaces, never mix spaces and tabs!).
  • Python2 vs Python3 print syntax: print imagePaths is Python2 syntax; in Python3, print is a function, so you need parentheses: print(imagePaths).
  • Function name typo: You defined getImagesWithID but tried to call getImageWithID (missing an s at the end).

Corrected Code

import os
import cv2
import numpy as np
from PIL import Image

recognizer = cv2.face.LBPHFaceRecognizer_create()
path = 'dataSet'

def getImagesWithID(path):
    # Properly indent the function body with 4 spaces
    imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
    print(imagePaths)  # Python3-compliant print function syntax

# Call the correctly named function
getImagesWithID(path)

Quick Tips to Avoid This Error Later

  • Always use 4 spaces for indentation (most code editors let you set Tab to insert 4 spaces automatically).
  • Turn on "show whitespace" in your editor to spot mixed spaces/tabs easily—this is a top culprit for indent errors.
  • Double-check function names when calling them—typos are easy to miss but break code fast!
  • Keep Python3 syntax rules in mind (like print() as a function) since you’re running Python 3.6.4.

内容的提问来源于stack exchange,提问作者Muhammad Adnan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:23:01