首页 文章

AttributeError:'module'对象没有属性'face'即使安装了opencv-contrib-python [关闭]

提问于
浏览
0

运行django服务器时出错 . 我通过pip安装了opencv-python和opencv-contrib-python . 仍然得到同样的错误 . 有什么建议?

Performing system checks...

Unhandled exception in thread started by 
Traceback (most recent call last):
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper fn(*args, **kwargs)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
    self.check(display_num_errors=True)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check include_deployment_checks=include_deployment_checks,
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks return checks.run_checks(**kwargs) 
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config return check_resolver(resolver)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver return check_method()
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check for pattern in self.url_patterns:
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__res = instance.__dict__[self.name] = self.func(instance)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance)
  File "/home/auxouser/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/auxouser/Auxo/projects/training-ds/Day-9/Face_Recognition/Face_Recognition/urls.py", line 3, in 
    from MyAPP import views
  File "/home/auxouser/Auxo/projects/training-ds/Day-9/Face_Recognition/MyAPP/views.py", line 12, in 
    recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: 'module' object has no attribute 'face'

1 回答

  • 1

    您的项目中可能有一个名为 cv.py (或本例中为 cv2.py )的模块 - 这意味着 import cv2 正在导入您自己的模块,而不是opencv, cv2.face 将失败 .

    删除.py文件和生成的.pyc,导入应该再次起作用 .

相关问题