ImportError: Cannot import MPTTModel name

I took steps in the tutorial " http://django-mptt.github.com/django-mptt/tutorial.html "

but it still gives me an import error, I double-check the code for mptt and find that the MPTTMODEL class exists in the mptt model file>

Validating models... Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1ec4710>> Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/commands/runserver.py", line 91, in inner_run self.validate(display_num_errors=True) File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 266, in validate num_errors = get_validation_errors(s, app) File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/validation.py", line 30, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 158, in get_app_errors self._populate() File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 67, in _populate self.load_app(app_name) File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 88, in load_app models = import_module('.models', app_name) File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module __import__(name) File "/home/kareemhashem/espace/sharek/core/models.py", line 12, in <module> from mptt.models import MPTTModel, TreeForeignKey ImportError: cannot import name MPTTModel 
+4
source share
1 answer

One thing you could try: go to the console and type: python (to get the python console) and then type: from mptt.models import MPTTModel

If this gives you an error, since mptt is not installed correctly.

If you use pip , you can easily do: pip install django-mptt or try pip install django-mptt --upgrade to upgrade your installation. Your installation may have failed.

If you are not using pip or virtualenv, I highly recommend it. The beginning is a little tough, but installing it is even worse. See These Resources to Get Started: 1 , 2

If you have successfully installed mptt and you still cannot import it, the folder where you placed mptt is probably not accessible to python. So add the path where mptt will be used for your PYTHONPATH. See the thread on how to do this.

+6
source

Source: https://habr.com/ru/post/1436176/


All Articles