gpt4 book ai didi

python - DeprecationWarning : Using or importing the ABCs from 'collections' instead of fr om 'collections.abc' is deprecated, 在 3.8 中它将停止工作

转载 作者:行者123 更新时间:2023-12-05 06:11:54 25 4
gpt4 key购买 nike

我从 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)

最佳答案

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

此问题已得到修复: https://github.com/django/django/commit/aba9763b5117494ca1ef1e420397e3845ad5b262

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

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

关于python - DeprecationWarning : Using or importing the ABCs from 'collections' instead of fr om 'collections.abc' is deprecated, 在 3.8 中它将停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63761805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com