Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django upgrade from 1.7.1 to 1.9.2. ImportError: cannot import name 'importlib'

I've just upgraded Django from 1.7.1 to 1.9.2. When I run the server I get:

from django.utils import importlib
ImportError: cannot import name 'importlib'

I noticed that there is no importlib.py file inside /lib/python3.4/site-packages/django/utils like it used to be in the previous version. Has anyone fixed this issue?

like image 951
Torostar Avatar asked Feb 11 '16 19:02

Torostar


1 Answers

django.utils.importlib was deprecated in Django 1.7 and removed in Django 1.9. Change your imports from:

from django.utils import importlib

to

import importlib

Before you upgrade Django, it's a good idea to read through the release notes to check for backwards incompatible changes like this. If you upgrade from 1.7 to 1.8 and then 1.8 to 1.9, it's less likely that your code will break, because Django 1.8 will show deprecation warnings which you can fix.

like image 106
Alasdair Avatar answered Sep 20 '22 20:09

Alasdair