2

I am new to Django. I got a Django rest project. When i run it, an error shows as

from django.utils.importlib import import_module
ImportError: No module named importlib

I tried installing importlib with the command

pip install importlib

Then it shows

Requirement already satisfied: importlib in ./lib/python2.7/site-packages/gcm/utils.py"

So how coild i install importlib package?

Hari Krishnan
  • 5,992
  • 9
  • 37
  • 55
  • possible duplicate of [Cannot import importlib](https://stackoverflow.com/questions/41997496/cannot-import-importlib) – Manoj Dec 18 '17 at 11:33

2 Answers2

6

You don't. importlib is part of python since v2.7. The project you want to run seems to be an old project that still uses the compatibility module provided by old Django versions for when it supported python 2.6. It's been obsolete since Django 1.7. That means it's twofold outdated.

Replace all occurences of django.utils.importlib with importlib. But the project being clearly outdated, you will probably run into many other issues.

spectras
  • 13,105
  • 2
  • 31
  • 53
  • 1
    its occurences are within inbuilt files like "Fileproject/local/lib/python2.7/site-packages/appconf/utils.py"". so changing that maynot be appropriate – Hari Krishnan Jun 03 '17 at 16:46
  • @HariKrishnan> it's not inbuilt, it's part of `appconf` third-party package, a very old package, the features of which are included in base Django since version 1.9. You should have shown the full exception stack in your question, would have made it possible to spot it. It will be hard to go any further as, if you look at the exact code in appconf, it's just hiding another exception that occurred while importing something else. It has nothing to do with importlib at all. – spectras Jun 05 '17 at 00:25
  • @HariKrishnan> looking at the package code, I think you probably have an old version installed. It's only compatible with Django 1.9 starting from appconf v1.0. Anyway, you should get rid of it. – spectras Jun 05 '17 at 00:43
0

As suggested in the comments the importlib is part of django-appconf which is later deprecated. You need to install approriate version of django-appconf.

pip install django-appconf==1.0.2