Cannot import importlib
Asked Answered
D

2

0

I am trying to use Listfield from djangotoolbox.fields but it is giving me an error saying :

Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/coderahul/Desktop/Experiment Box/Innovation/Codeplay/codeplay/data_aggregator/models.py", line 9, in <module>
from djangotoolbox.fields import ListField
File "/Library/Python/2.7/site-packages/djangotoolbox/fields.py", line 4, in <module>
from django.utils.importlib import import_module
ImportError: No module named importlib

What am I doing wrong?

Dexterous answered 2/2, 2017 at 8:34 Comment(2)
Possible duplicate of How to import a module in Python with importlib.import_moduleFlagellate
Importlib is not a Django util, it's in the Python standard. Just from importlib import import_module.Mouldon
M
2

django.utils.importlib is a compatibility library for when Python 2.6 was still supported. It has been obsolete since Django 1.7, which dropped support for Python 2.6, and is removed in 1.9 per the deprecation cycle.

Try this

from importlib import import_module

source here.

Marcello answered 2/2, 2017 at 8:36 Comment(3)
Where should I add this? In models?Dexterous
I favour you to use django-1.9 for djangotoolbox otherwise use NoSQL database if you want Listfield .Marcello
bcoz djangotoolbox is not maintained and well documented.Marcello
M
0

use from importlib import import_module

Marquis answered 2/2, 2017 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.