gpt4 book ai didi

python - Django 导入错误 : cannot import name 'python_2_unicode_compatible'

转载 作者:行者123 更新时间:2023-12-03 15:04:33 27 4
gpt4 key购买 nike

我正在建立一个网站,我试图创建一个自定义的用户到用户的消息传递系统,所以我安装了 django-messages也许还有其他一些事情,突然当我尝试运行我的服务器时,我收到以下错误:

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django_messages\models.py", line 9, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\encoding.py)

对我来说这听起来像中文,我不明白这个错误的一行,有人可以帮助我吗?
我做了一些研究,看起来它与包名 six有关。但我无法找到解决方案。如果需要,我可以为您提供我的代码,但我不知道您需要哪个文件,因此请随时在评论中索取文件,我将相应地编辑我的帖子。

提前致谢 !

最佳答案

您正在使用 Django 3,其中所有 the Python 2 compatibility APIs曾经与 Django 捆绑的那些被删除了。 django-messages仍然依赖于这些,并且正在尝试导入它们但失败了。

您要么需要降级到 Django 2.2,要么等待 django-messages更新以支持 Django 3。

这适用于您收到此类错误的任何库 - 这意味着该库与 Django 3 尚不兼容。

关于python - Django 导入错误 : cannot import name 'python_2_unicode_compatible' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59583726/

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