Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django error cannot import name 'RemovedInDjango30Warning'

Guys im fairly new to Django and I just started working on a personal project and decided that ill-use pycharm (i think its related to the error, or not).

when I run python manage.py runserverI get the error posted below. I did a bit of googling and looks like its caused by inconsistency with Django versions.

I currently have Django 3.0 and I checked both globally and in the venv.

I tried to start a project outside of py charm and im running into the same issue. idk what I need to do to start using Django again. Did anyone run into this? Is this because of pycharm? If so what can I do to fix the issue?

(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'
like image 428
Aiden Campbell Avatar asked Dec 02 '19 23:12

Aiden Campbell


4 Answers

This appears to be from a corrupt Django installation in site-packages. Remove Django and install it again.

For me, I was upgrading an existing project from Django 2.2.6 to 3.1.7. It appears that somehow files from 2.2.6 were still hanging around. I had to run pip uninstall django twice to get back to a clean slate and then pip install django to install the latest version.

like image 92
Code-Apprentice Avatar answered Oct 19 '22 04:10

Code-Apprentice


This is caused by conflicts in Django versions as seen here.

ImportError: cannot import name 'RemovedInDjango30Warning'

Try uninstalling django

sudo pip uninstall django

and reinstall with a version lower than 3.0

sudo pip install django==2.2

Edit

If you wish to use different versions of Django you can use virtual environments.

First create a requirements.txt example from here

You can generate your project’s requirements by running the pip freeze command that lists all packages that are installed in your local machine with their versions.

pip freeze > requirements.txt

Do note that this process can lead to certain unnecessary packages being written to the requirements file which are installed in your local machine but not required for the project. You must manually edit the requirements file in that case.

Then create your virtual environment

Step 1 install virtualenv

pip install virtualenv

Step 2 create virtual enviroment

virtualenv env

Step 3 Activate your environment

env\Scripts\activate

When you wish to deacitvate

deactivate

Step 4 Edit your requirements.txt to have the packages you'll need for your project.

Step 5 install requirements.txt (in same dir)

pip install -r requirements.txt

Form infomation on deployment with mod_wsgi and Apache try here

like image 10
recurseuntilfor Avatar answered Oct 19 '22 05:10

recurseuntilfor


Comment out the following line:

from django.utils.deprecation import RemovedInDjango30Warning

in the files below:

python3.6/site-packages/django/contrib/admin/templatetags/admin_static.py
python3.6/site-packages/django/contrib/staticfiles/templatetags/staticfiles.py
like image 2
y durga prasad Avatar answered Oct 19 '22 05:10

y durga prasad


This is caused by django versions. You probably upgraded it.

If you do not want to go back to version 2, create a virtual environment and do pip install django==2.2

like image 1
Not Me Avatar answered Oct 19 '22 03:10

Not Me