Reputation: 101
I watched a tutorial which was coded in Python about OpenCV. I get an error when I try to import a class. The error is below.
Traceback (most recent call last):
File "webstreaming.py", line 1, in <module>
from pyimagesearch.motion_detection import SingleMotionDetector
ImportError: cannot import name 'SingleMotionDetector' from 'pyimagesearch.motion_detection' (/home/pi/Desktop/Denemeler/pyimagesearch/motion_detection/__init__.py)
Here is my directory tree.
.
├── pyimagesearch
│ ├── __init__.py
│ └── motion_detection
│ ├── __init__.py
│ └── singlemotiondetector.py
├── templates
│ └── index.html
└── webstreaming.py
I checked stackoverflow but none of the answers worked for me. Thanks.
Upvotes: 0
Views: 1200
Reputation: 2116
When a regular package is imported, this init.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace.
Since __init__.py
doesn't have module imports, We'll have to manually import the required sub modelues from the respective file. SingleMotionDetector
is in singlemotiondetector.py
, the import should look like
from pyimagesearch.motion_detection.singlemotiondetector import SingleMotionDetector
Reference : python Packages
Upvotes: 1