【问题标题】:DeprecationWarning: Using or importing the ABCs from 'collections' instead of fr om 'collections.abc' is deprecated, and in 3.8 it will stop working弃用警告:不推荐使用或从 'collections' 而不是从 'collections.abc' 导入 ABC,在 3.8 中它将停止工作
【发布时间】:2020-09-06 07:36:46
【问题描述】:

我从 github 下载了一个代码并尝试通过在 git bash 中运行命令来运行它:python manage.py runserver

但我遇到了这个错误:

DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

已按照此答案 How to use collections.abc from both Python 3.8+ and Python 2.7 中的建议对我的 manage.py 文件进行了更改 但仍然面临同样的错误。

import os
import sys

try:
    from collections.abc import Callable
except ImportError:
    from collections import Callable

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
execute_from_command_line(sys.argv)

【问题讨论】:

  • 基本 DJango 教程在 py manage.py runserver 失败并出现同样的错误。

标签: python collections manage.py django-manage.py


【解决方案1】:

DeprecationWarning 是由 django 本身发生的导入引起的。 这是旧版本 Django 中的一个已知问题: https://code.djangoproject.com/ticket/30078

它已被修复: https://github.com/django/django/commit/aba9763b5117494ca1ef1e420397e3845ad5b262

根据该提交的发布标签,该修复似乎首次出现在 Django 2.1 版中。

解决方案是使用更新版本的 Django。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    相关资源
    最近更新 更多