7

In one of my django tests, I use django.utils.importlib.import_module similarly to how it is used here.

On upgrading to django 1.8, I get a deprecation warning

test_views.py:20: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  from django.utils.importlib import import_module

Is the recommended practice now to use import_module from importlib in the standard library (which seems to work fine)? Or is the recommended practice to avoid using import_module entirely?

Jonatas CD
  • 878
  • 2
  • 10
  • 19
mjandrews
  • 2,392
  • 4
  • 22
  • 39

2 Answers2

12

Based on the documentation (found by looking at the django deprecation timeline for 1.9 and following the link), your first suggestion seems to be correct: developers should use the standard importlib that is part of the standard library.

eykanal
  • 26,437
  • 19
  • 82
  • 113
8

Yes, django.utils.importlib.import_module is effectively the same thing as importlib.import_module. As long as you're not targeting a version of Python before 2.7, it is okay to just use importlib.import_module.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • it has problems with Python3 version < 3.4, because Django tries to use find_spec but find_spec was added only in 3.4. – dskarataev May 22 '16 at 06:21