docker容器运行Django镜像报错,看不懂,求指导~
运行容器后查看镜像,提示如下报错信息:
以下是全部报错信息:
```bash
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 393, in execute
self.check()
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 423, in check
databases=databases,
File "/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/checks.py", line 78, in check_dependencies
for engine in engines.all():
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 90, in
return [self[alias] for alias in self]
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "" , line 1006, in _gcd_import
File "" , line 983, in _find_and_load
File "" , line 967, in _find_and_load_unlocked
File "" , line 677, in _load_unlocked
File "" , line 728, in exec_module
File "" , line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/site-packages/rest_framework/templatetags/rest_framework.py", line 11, in
from rest_framework.compat import apply_markdown, pygments_highlight
File "/usr/local/lib/python3.7/site-packages/rest_framework/compat.py", line 71, in
import markdown
File "/usr/local/lib/python3.7/site-packages/markdown/__init__.py", line 29, in
from .core import Markdown, markdown, markdownFromFile # noqa: E402
File "/usr/local/lib/python3.7/site-packages/markdown/core.py", line 26, in
from . import util
File "/usr/local/lib/python3.7/site-packages/markdown/util.py", line 87, in
INSTALLED_EXTENSIONS = metadata.entry_points().get('markdown.extensions', ())
AttributeError: 'EntryPoints' object has no attribute 'get'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 75, in handle
self.check(databases=[database])
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 423, in check
databases=databases,
File "/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/checks.py", line 78, in check_dependencies
for engine in engines.all():
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 90, in
return [self[alias] for alias in self]
File "/usr/local/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "" , line 1006, in _gcd_import
File "" , line 983, in _find_and_load
File "" , line 967, in _find_and_load_unlocked
File "" , line 677, in _load_unlocked
File "" , line 728, in exec_module
File "" , line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.7/site-packages/rest_framework/templatetags/rest_framework.py", line 11, in
from rest_framework.compat import apply_markdown, pygments_highlight
File "/usr/local/lib/python3.7/site-packages/rest_framework/compat.py", line 71, in
import markdown
File "/usr/local/lib/python3.7/site-packages/markdown/__init__.py", line 29, in
from .core import Markdown, markdown, markdownFromFile # noqa: E402
File "/usr/local/lib/python3.7/site-packages/markdown/core.py", line 26, in
from . import util
File "/usr/local/lib/python3.7/site-packages/markdown/util.py", line 87, in
INSTALLED_EXTENSIONS = metadata.entry_points().get('markdown.extensions', ())
AttributeError: 'EntryPoints' object has no attribute 'get'
```
这个错误是在运行Django应用程序时出现的,看起来是在尝试导入markdown模块时出现了问题。这是因为在导入markdown模块时,有一些依赖项无法加载。具体来说,metadata.entry_points()调用出现问题,因为EntryPoints对象没有get方法。这个问题可能是由于依赖项版本不兼容造成的。
我建议你尝试升级相关依赖项,以便它们与Django兼容。你可以检查requirements.txt文件,以确定使用的依赖项和版本。你可以尝试使用最新版本的依赖项,并重新构建Django Docker映像。
如果升级依赖项不起作用,你可以检查是否有其他错误信息,这些信息可能有助于更好地诊断问题。此外,你可以在构建Docker映像时添加--no-cache选项,以确保重新构建所有内容,包括依赖项。
在 Docker 中启动 Django 镜像时,如果出现 'EntryPoints' object has no attribute 'get' 错误,可能是因为版本不兼容导致的。
这个问题通常是由于使用的 Django 版本与安装的 Python 版本不兼容所导致的。具体来说,如果使用的是 Django 3.1 或更高版本,并且安装的是 Python 3.5 或更低版本,就会出现这个错误。
解决方法是升级 Python 版本。可以使用 python --version 命令检查当前 Python 版本,如果版本过低,可以安装更高版本的 Python。在 Dockerfile 中可以指定需要的 Python 版本,例如:
FROM python:3.8
上面的代码指定了使用 Python 3.8 版本作为基础镜像,可以解决这个问题。
另外,也可以尝试更新依赖库的版本,例如更新 setuptools 和 wheel 版本,命令如下:
pip install --upgrade setuptools wheel
这样可以确保依赖库版本兼容,避免出现类似的错误。