运行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'
答案 0 :(得分:1)
您的项目中可能有一个名为cv.py
(在本例中为cv2.py
)的模块-这意味着import cv2
正在导入您自己的模块,而不是opencv,而{{1} }将失败。
删除您的.py文件和所生成的.pyc,导入应该会再次起作用。