Jupyter Notebook中ModuleNotFoundError: No module named 'object_detection'报错求助
ModuleNotFoundError: No module named 'object_detection' in Jupyter Notebook Hey there, I’ve dealt with this exact frustration before—installing a package thinking it’ll work, only to have Jupyter throw that missing module error. Let’s walk through the most reliable fixes:
First, confirm Jupyter is using the right Python environment
Jupyter often runs in a different environment than your terminal’s default. To check which Python executable your notebook is using, run this in a cell:import sys print(sys.executable)Copy that path, then open your terminal and install the package using that specific Python instance. For example, if the path is
/Users/you/venv/bin/python, run:/Users/you/venv/bin/python -m pip install object-detection-apiThis ensures the package is installed in the environment Jupyter is actually using.
Manually add the package path to Jupyter’s sys.path
If the package is installed but Jupyter can’t locate it, you can explicitly tell Python where to find it. First, find the installation location ofobject-detection-apiby running this in your terminal:pip show object-detection-apiLook for the
Locationline (it’ll be something like/usr/local/lib/python3.10/site-packages). Then, add this at the top of your notebook before importingobject_detection:import sys sys.path.append("/the/location/you/found")If you don’t see an
object_detectionfolder directly in that location, check if it’s nested inside another directory (liketensorflowor a subfolder) and add that parent path instead.Use the official TensorFlow Object Detection API setup (if the PyPI package fails)
Sometimes the PyPIobject-detection-apiwrapper doesn’t set up the module structure correctly. The official approach is more reliable:- Clone the TensorFlow Models repository:
git clone https://github.com/tensorflow/models.git - Navigate to the research directory and compile the protobuf files:
cd models/research protoc object_detection/protos/*.proto --python_out=. - Install the package locally:
pip install . - In your Jupyter notebook, add the necessary paths before importing:
import sys sys.path.append("/path/to/models/research") sys.path.append("/path/to/models/research/slim")
- Clone the TensorFlow Models repository:
These steps almost always resolve the module not found issue for me. Give them a try!
内容的提问来源于stack exchange,提问作者zasha




