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

Windows下TensorFlow Object Detection API报错:ModuleNotFoundError: No module named 'utils'

Fixing "ModuleNotFoundError: No module named 'utils'" for TensorFlow Object Detection API on Windows 10

I recently ran into a frustrating issue while setting up the TensorFlow Object Detection API on Windows 10 (Python 3.6, TensorFlow 1.4.0): my scripts would only run if they were placed directly in the cloned models repository directory. Move them anywhere else, and I'd hit a ModuleNotFoundError: No module named 'utils'. Turns out this was because I hadn't properly configured the Windows equivalent of the Linux export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim environment variable.

Pre-Deployment Steps I Completed

  • Installed TensorFlow and core tools via pip3
  • Opened an administrator Command Prompt and ran:
    pip3 install pillow lxml jupyter matplotlib
    
  • Cloned the TensorFlow models repository to C:\Users\cdahms\Documents\models
  • Downloaded Google Protobuf v3.4.0 for Windows, extracted it to C:\Program Files\protoc-3.4.0-win32
  • Navigated to models\research and ran the Protobuf compilation command:
    "C:\Program Files\protoc-3.4.0-win32\bin\protoc.exe" object_detection/protos/*.proto --python_out=.
    
    Verified all corresponding .py files were generated successfully
  • Navigated to the object_detection directory, launched Jupyter Notebook, and confirmed object_detection_tutorial.ipynb ran without issues
  • Exported the notebook as object_detection_tutorial.py, which worked fine in the repository directory but failed elsewhere

The Fix: Configuring Windows Environment Variables

To get Python to recognize the API's module paths globally, follow these steps:

  1. Open System Advanced Settings: Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
  2. In the "System variables" section, click "New":
    • Variable name: PYTHONPATH
    • Variable value: Add these two paths separated by a semicolon:
      C:\Users\cdahms\Documents\models\research;C:\Users\cdahms\Documents\models\research\slim
      
  3. Locate the PATH variable in System variables, click "Edit", and append %PYTHONPATH% to the end
  4. Restart your computer (critical for the environment variables to take effect)
  5. After restarting, you can run object_detection_tutorial.py (or any other API script) from any directory without encountering the utils module error

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:29:03