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\researchand ran the Protobuf compilation command:
Verified all corresponding"C:\Program Files\protoc-3.4.0-win32\bin\protoc.exe" object_detection/protos/*.proto --python_out=..pyfiles were generated successfully - Navigated to the
object_detectiondirectory, launched Jupyter Notebook, and confirmedobject_detection_tutorial.ipynbran 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:
- Open System Advanced Settings: Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
- 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
- Variable name:
- Locate the
PATHvariable in System variables, click "Edit", and append%PYTHONPATH%to the end - Restart your computer (critical for the environment variables to take effect)
- After restarting, you can run
object_detection_tutorial.py(or any other API script) from any directory without encountering theutilsmodule error
内容的提问来源于stack exchange,提问作者cdahms
相关产品推荐
相关产品推荐

