pycharm django错误无法导入名称'RemovedInDjango30Warning'

kd3sttzy  于 2022-12-23  发布在  PyCharm
关注(0)|答案(7)|浏览(330)

伙计们,我是Django的新手,我刚刚开始做一个个人项目,我决定不正确地使用pycharm(我认为这与错误有关,或者没有)。
当我运行python manage.py runserver时,我得到了下面的错误。我在谷歌上搜索了一下,看起来像是与Django版本不一致造成的。
我现在有Django 3.0,我在全球和venv都查过了。
我试图在py charm之外开始一个项目,我遇到了同样的问题。idk我需要做什么才能再次开始使用Django。有人遇到过这个问题吗?是因为pycharm吗?如果是这样,我可以做些什么来修复这个问题?

(venv) aiden@aiden-XPS-15-9570:~/PycharmProjects/NewsAggregator$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/aiden/.local/lib/python3.6/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 "/home/aiden/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
    module = import_module(entry[1])
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/aiden/.local/lib/python3.6/site-packages/django/contrib/admin/templatetags/admin_static.py", line 5, in <module>
    from django.utils.deprecation import RemovedInDjango30Warning
ImportError: cannot import name 'RemovedInDjango30Warning'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/core/management/base.py", line 395, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/aiden/.local/lib/python3.6/site-packages/django/core/management/base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/contrib/admin/checks.py", line 76, in check_dependencies
    for engine in engines.all():
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/utils.py", line 90, in all
    return [self[alias] for alias in self]
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/utils.py", line 90, in <listcomp>
    return [self[alias] for alias in self]
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/utils.py", line 81, in __getitem__
    engine = engine_cls(params)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 25, in __init__
    options['libraries'] = self.get_templatetag_libraries(libraries)
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
    libraries = get_installed_libraries()
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
    for name in get_package_libraries(pkg):
  File "/home/aiden/.local/lib/python3.6/site-packages/django/template/backends/django.py", line 125, in get_package_libraries
    "trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'django.contrib.admin.templatetags.admin_static': cannot import name 'RemovedInDjango30Warning'
s71maibg

s71maibg1#

这是由Django版本中的冲突引起的,如图所示。
导入错误:无法导入名称"RemovedInDjango30警告"
尝试卸载django

sudo pip uninstall django

并使用低于3.0的版本重新安装

sudo pip install django==2.2
    • 编辑**

如果你想使用不同版本的Django,你可以使用虚拟环境。
首先从here创建requirements.txt示例
您可以通过运行pip freeze命令来生成项目的需求,该命令列出了安装在本地计算机上的所有包及其版本。

pip freeze > requirements.txt

请注意,这个过程可能会导致某些不必要的包被写入需求文件,这些包安装在您的本地计算机上,但项目并不需要。在这种情况下,您必须手动编辑需求文件。
然后创建虚拟环境
步骤1安装virtualenv

pip install virtualenv

第二步创建虚拟环境

virtualenv env

步骤3激活环境

env\Scripts\activate

当你想去激活

deactivate

第4步编辑requirements.txt文件,以获得项目所需的包。
步骤5安装requirements.txt(在同一目录中)

pip install -r requirements.txt

使用mod_wsgi和Apache try here进行部署的表单信息

x7rlezfr

x7rlezfr2#

注解以下行:

from django.utils.deprecation import RemovedInDjango30Warning

在以下文件中:

python3.6/site-packages/django/contrib/admin/templatetags/admin_static.py
python3.6/site-packages/django/contrib/staticfiles/templatetags/staticfiles.py
lnvxswe2

lnvxswe23#

这可能是由于站点包中的Django安装损坏造成的。请删除Django并重新安装。
对我来说,我正在将一个现有的项目从Django 2.2.6升级到3.1.7。看起来2.2.6的文件还在附近。我必须运行pip uninstall django两次才能回到干净的状态,然后运行pip install django安装最新版本。

hlswsv35

hlswsv354#

这是由django版本引起的,你可能升级了它。
如果你不想回到版本2,创建一个虚拟环境并执行pip install django==2.2

kcrjzv8t

kcrjzv8t5#

这个错误取决于python,pip和django的版本。这个错误通常在python2上运行最新的django版本时出现。
安装python3版本
使用命令,如
pip3安装django
python3 manage.py运行服务器

vuv7lop3

vuv7lop36#

我遇到了同样的问题。这个问题发生是由于2版本的python或django。所以,如果你是通过虚拟环境(venv)运行你的项目,请检查python版本在它。通过直接进入以下:

myproject/venv/lib/pythonx.y

请确保x.y是你在你的项目中使用的python版本.或者如果你不是通过venv运行你的项目,请检查你的项目正在使用和运行的python版本.

python --version
n6lpvg4x

n6lpvg4x7#

我只想说,当你因为某些原因卸载了django,当你再次安装它的时候,你可能会出现这个问题,只要在django/utils/ www.example.com中添加'class RemovedInDjango 30 warning:pass'deprecation.py就可以了。

相关问题