ImportError:无法导入名称“MyLibrary”

2024-10-01 15:29:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我看了一个用Python编写的关于OpenCV的教程。我尝试导入类时出错。错误如下

 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)

这是我的目录树

.
├── pyimagesearch
│   ├── __init__.py
│   └── motion_detection
│       ├── __init__.py
│       └── singlemotiondetector.py
├── templates
│   └── index.html
└── webstreaming.py

我检查了stackoverflow,但没有一个答案对我有用。谢谢


Tags: frompyimportmostinit错误教程opencv
1条回答
网友
1楼 · 发布于 2024-10-01 15:29:04

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.

由于__init__.py没有模块导入,我们必须从相应的文件手动导入所需的子模型SingleMotionDetector在{}中,导入应该如下所示

from pyimagesearch.motion_detection.singlemotiondetector import SingleMotionDetector

参考:python Packages

相关问题 更多 >

    热门问题