ImportError: cannot import name 'six' from 'django.utils' - django

Recently, I upgraded the version of Django framework from 2.0.6 to 3.0 and suddenly after calling python manage.py shell command, I got this exception:
ImportError: cannot import name 'six' from 'django.utils' (/path-to-project/project/venv/lib/python3.7/site-packages/django/utils/init.py)
Full trace:
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/__init__.py", line 1, in <module>
from .checks import check_settings # noqa: F401
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/checks.py", line 7, in <module>
from django.utils import six
Similar Questions:
I read this Question and this django-3.0, release note , but those resources couldn't help me.

Why this error/exception?
From django-3.0release notes,
django.utils.six - Remove usage of this vendored library or switch to six.
means, django.utils.six module was removed from django-3.0 onwards.
My codebase isn't using "django.utils.six" module, then why this error?
This import error could be raised because of two reasons,
Most importantly, any of your installed packages are using the django.utils.six module
or maybe your codebase using the django.utils.six module
NOTE: Most of the time the first reason is the villain 😖😖
How can I identify which package is causing the error/exception?
The easy way is, look into your last few lines of error traceback, and it will tell you which package is causing the exceptions.
Examples
Corsheaders
In this example, corsheaders module caused the the import error
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/__init__.py", line 1, in
from .checks import check_settings # noqa: F401
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/checks.py", line 7, in
from django.utils import six
Example-2
In this example, jsonfield module caused the the import error
File "d:\production\myproject\venv\lib\site-packages\jsonfield\fields.py", line 21, in
from .encoder import JSONEncoder
File "d:\production\myproject\venv\lib\site-packages\jsonfield\encoder.py", line 2, in
from django.utils import six, timezone
ImportError: cannot import name 'six' from 'django.utils' (d:\production\myproject\venv\lib\site-packages\django\utils\__init__.py)
Example-3
In this example parler module caused the import error
...
File "/path/to/project/venv/lib/python3.8/site-packages/parler/utils/conf.py", line 10, in
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/path/to/project/venv/lib/python3.8/site-packages/django/utils/__init__.py)
Example-4
In this example django_mysql module caused the import error
File "/home/jerin/.virtualenvs/webscraperio/lib/python3.6/site-packages/django_mysql/checks.py", line 9, in
from django_mysql.utils import collapse_spaces
File "/home/jerin/.virtualenvs/webscraperio/lib/python3.6/site-packages/django_mysql/utils.py", line 17, in
from django.utils import six
ImportError: cannot import name 'six'
What is the solution?
If the error raised because of some third-party packages like django-cors-headers,django-jsonfield, etc upgrade the corresponding package versions to latest versions. If you are already using the latest version, report an issue with the developer.
If the error raised because from your codebase, use six package instead of django.utils.six module

The Django 3.0.0 release notes specify that certain private Python 2 compatibility APIs were removed. Among those was django.utils.six.
For this error specifically, #WillemVanOnsem noted that the module corsheaders was referencing this module.
For others encountering this same thing, looking at the file path on the last line of the stack trace can help with identifying the problematic module. Another example of this I've seen is:
...
File "/path/to/project/venv/lib/python3.8/site-packages/parler/utils/conf.py", line 10, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/path/to/project/venv/lib/python3.8/site-packages/django/utils/__init__.py)
The module causing the issue, in this case, was parler. I hope this helps any others who encounter this issue.

Install this library: django-utils-six 2.0 for Django >= 3.
pip install django-utils-six

First, install six from pip
pip install six
Second, call six
from six import text_type
For me works, I have Django 3.0.4

As mentioned by Mohammad Masoumi, upgrading the packages will resolve the issue because corsheaders is supporting Django 3.0 now.
pip install --upgrade django-cors-headers
I also upgraded djangorestframework and drf_yasg to avoid this ImportError.

You need to update the cors headers package:
pip3 install six
pip3 install --upgrade django-cors-headers

Exception:
File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/usr/local/lib/python3.8/dist-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/usr/local/lib/python3.8/dist-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.8/dist-packages/django_celery_beat/models.py", line 6, in <module>
import timezone_field
File "/usr/local/lib/python3.8/dist-packages/timezone_field/__init__.py", line 1, in <module>
from timezone_field.fields import TimeZoneField
File "/usr/local/lib/python3.8/dist-packages/timezone_field/fields.py", line 5, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/usr/local/lib/python3.8/dist-packages/django/utils/__init__.py)
Solution:
vi /usr/local/lib/python3.8/dist-packages/timezone_field/fields.py
Change:
from django.utils import six
To:
import six

I had the same problem.
My issue was using:
pip install django_taggit==0.22.2
I resolved this when I did:
pip install django_taggit==1.2.0
because that is the latest version.

There are a number of libraries and add-ons to Django that use django.utils.six, which of course are now broken. The main one of concern is mysql-connector-python (8.0.18). The simple solution is to use the library external to Django, but the authors of these libraries will need to make their changes (or you could temporarily make the changes yourself....replace django.utils.six with six).

Folks' ideal solution is an upgrade and clean usage, but a workaround for folks in dire straits is simple enough.
In Django utils create a new file six.py and inside the file put:
import six
NOTE: Not a solution but a workaround for immediate patching

I resolved this issue by installing a higher version of corsheader package.
corsheader v3.3.0 supports Django 3.0.x
django-cors-headers==3.3.0

JSONField Solution:
I used jsonfield and jsonfiled2 packages. But in both cases, I faced the same error.
My problem solved when I have installed django-jsonfield package and uninstall the rest of the packages (related to jsonfield).
# In case you have installed the following packages, otherwise ignore them.
pip uninstall jsonfield
pip uninstall jsonfield2
pip install django-jsonfield
Usage:
from django.db import models
from jsonfield import JSONField
class ModelName(models.Model):
json_field = JSONField()

I had the exact same problem. Let me tell you how I solved it (fortunately it was simple to do).
So, what's going on?
You have to pay attention to the traceback Django is telling you (pro tip: start from the bottom):
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/checks.py", line 7, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/path-to-project/project/venv/lib/python3.7/site-packages/django/utils/init.py)
It tells you two important things:
What's going on: ImportError: cannot import name 'six' from 'django.utils'
Where it's happening: /lib/python3.7/site-packages/corsheaders/checks.py", line 7, in <module>
It is first telling you it cannot import the six module from django.utils, which is quite logical since Django has deprecated the module in Django 3.0.
Now you may ask:
but hey, I wasn't using that module!!
You're right, but a dependency was :)
Which dependency?
I'm glad you asked...
This one ==> /lib/python3.7/site-packages/corsheaders/checks.py, corsheaders was importing the module here: from django.utils import six in checks.py (in line 7).
What's the solution?
This issue is generally solved by updating the package that created the problem in the first place. They probably removed that import and replaced it with something else, if necessary.
Go to the command line and type:
pip install corsheaders -U
What generated the problem?
Django stopped supporting Python 2. Since django.utils.six provided "Utilities for writing code that runs on Python 2 and 3", it was not longer necessary to support this module, so it was deprecated in Django 3.

Django six is not available for Django versions higher than django2, so a quick fix is to install it via pip:
pip install django-utils-six
Then you should be good to go

If the error raised because of some third-party packages and you are already using the latest version, report an issue with the developer. If you did that but you really need a urgent fix, this strategy could make the third party package happy:
try:
# six removed since Django 3.0
from django.utils import six
except ImportError:
import six
import sys
sys.modules["django.utils.six"] = six
# similarly for any other six sub-module required:
sys.modules["django.utils.six.moves"] = six.moves
# finally, import the outdated third-party package below:
import outdated_library

As I understand, You just need to delete tokens.py file at all
if You have a greater version of Django.
And remove all imports from .tokens in other files such as views.py as well.

FYI I got this same error from using the package django-braces. I had used Conda to install it: conda install -c conda-forge django-braces. By default as of the time of this answer (Jan 24, 2023) conda-forge installs version 1.13 of django-braces, which gives rise to the "cannot import 'six' from django.utils" error.
To fix it, I did the following:
conda remove django-braces
pip install django-braces
This removes django-braces v1.13 and replaces it with v1.15, which solves the problem. Happy django-ing everyone.

Related

Apache + mod_wsgi + Django + dataclasses stopped working after upgrade to python3.10

After upgrading to python3.10 code with dataclasses stopped working with mod_wsgi.
If a class is created with #dataclass decorator (with just a single attribute x: str) and then instantiated somewhere in apps.py at module level, an exception is thrown. The reason is missing generated __init__ method (I confirmed that everything works if I define __init__ manually). Unfortunately, in real project it's part of external library and dataclass is instantiated in imported module, so there's no way to define __init__ by hands. The code without changes (all packages have same versions too) works with python3.9.
To be clear, here's the code:
# models.py
from dataclasses import dataclass
#dataclass
class Test:
foo: str
# apps.py
from django.apps import AppConfig
from .models import Test
Test('bar') # Error is thrown here
class AppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app'
It seems like there's a bug somewhere. I also know that mod_wsgi only support python up to 3.8, according to data on pypi, but can't believe the answer is "Look for other wsgi solution or don't upgrade yet" (if so - tell me too, it might be true). You might notice that Django is of version 3.2 in requirements while 4.0 is available: I tried upgrading on this demo project, nothing has changed, plus django 3.2 claims to support python3.10 too (on the real project I can't upgrade due do dependencies using deprecated functions). So my questions are:
Am I missing something that should be changed on upgrade to python 3.10 in this case?
If it's some inner bug, where should I report it --- to python 3.10, to mod_wsgi or to Django?
The traceback is:
Traceback (most recent call last):
File "/var/www/html/proof/proof/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.10/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 124, in create
mod = import_module(mod_path)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/var/www/html/proof/app/apps.py", line 6, in <module>
Test('bar')
TypeError: Test() takes no arguments
Here's repo with more details and full project layout, also Dockerfile present so you can reproduce easily.

Getting error cannot import name 'six' from 'django.utils' when using Django 3.0.0 latest version

Currently I have upgraded version of Django 2.2 to 3.0 and suddenly getting error like below.
ImportError: cannot import name 'six' from 'django.utils'
I have checked
Traceback is like below.
Traceback (most recent call last):
File "c:\Users\admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Python37\Lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Python37\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Python37\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\production\myproject\erp_project\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "d:\production\myproject\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "d:\production\myproject\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "d:\production\myproject\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "d:\production\myproject\venv\lib\site-packages\django\apps\registry.py", line 92, in populate
app_config = AppConfig.create(entry)
File "d:\production\myproject\venv\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "d:\production\myproject\venv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "d:\production\myproject\venv\lib\site-packages\post_office\__init__.py", line 3, in <module>
from .backends import EmailBackend
File "d:\production\myproject\venv\lib\site-packages\post_office\backends.py", line 6, in <module>
from .settings import get_default_priority
File "d:\production\myproject\venv\lib\site-packages\post_office\settings.py", line 101, in <module>
context_field_class = import_attribute(CONTEXT_FIELD_CLASS)
File "d:\production\myproject\venv\lib\site-packages\post_office\compat.py", line 45, in import_attribute
module = importlib.import_module(module_name)
File "d:\production\myproject\venv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "d:\production\myproject\venv\lib\site-packages\jsonfield\__init__.py", line 1, in <module>
from .fields import JSONField, JSONCharField # noqa
File "d:\production\myproject\venv\lib\site-packages\jsonfield\fields.py", line 21, in <module>
from .encoder import JSONEncoder
File "d:\production\myproject\venv\lib\site-packages\jsonfield\encoder.py", line 2, in <module>
from django.utils import six, timezone
ImportError: cannot import name 'six' from 'django.utils' (d:\production\myproject\venv\lib\site-packages\django\utils\__init__.py)
I have checked in folder Lib\site-packages\django\utils and not found and six.py file but still from Lib\site-packages\jsonfield\encode.py containing line from django.utils import six, timezone which trying to import six but not able to find.
Earlier version of django containing six.py file in folder Lib\site-packages\django\utils.
Any idea how to solve this ?
Short answer: you might want to abandon django-jsonfield.
Based on the traceback, you are using the django-jsonfield package [GitHub], and this is a known issue [GitHub-issue]. It depends on the django.utils.six module, but that module has been removed in django-3.0.
At the moment, you thus can not use django-3.0 with django-jsonfield, and since the last commit to this project is from October 2017, perhaps the project is not that "active" anymore, and it thus might take a very long time (or even never) get fixed. The successor of django-jsonfield is jsonfield2 ([GitHub]). It was made compatible with django-3.0 by a pull request in October (2019) [GitHub-pr].
in order to use the six module you can install it directly using pip and then modify the django-jsonfield package accordingly . What I mean is find the files in the package where there is from django.utils import six and replace them with import six. Then it should be working. I faced the same issue when using djongo with django 3.0. I found the respective file and replaced it with the above suggestion. Please note that it is never recommended to do this if you are working on a production level or enterprise level project. I did it for my pet project.
A specified in Django 3.0 release note, django.utils.six is removed.
In case you need it, it is advised to use pypi packages instead
In your case, jsonfield package might be replaced by native Django's JSON Field.
Another solution would be to fork jsonfield package yourself to solve you issue, or to make a PR on project's repo'
Short Answer
in Django 3.0 just install six:
pip install six
And just use it like:
import six
In my case it was django-haystac causing this error.
It helped me to upgrade the pip package to the newest beta.
pip install django-haystack==3.0b2

dreamhost python3 Django passenger setup import Cookie

I am trying to setup django with python3 on dreamhost.
I have setup a virtualenv as documented by them and installed all the pre-requisites. I have gotten runserver working
The problem comes with passenger setup. The error log shows that I am unable to import a module named Cookie, resulting out of further errors.
This is the traceback:
File "/home/user/path/env/lib/python3.4/imp.py", line 171, in load_source
module = methods.load()
File "<frozen importlib._bootstrap>", line 1220, in load
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "passenger_wsgi.py", line 17, in <module>
from django.core.wsgi import get_wsgi_application
File "/home/user/path/env/lib/python3.4/site-packages/django/core/wsgi.py", line 2, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "/home/user/path/env/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 11, in <module>
from django import http
File "/home/user/path/env/lib/python3.4/site-packages/django/http/__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
File "/home/user/path/env/lib/python3.4/site-packages/django/http/cookie.py", line 5, in <module>
from django.utils.six.moves import http_cookies
File "/home/user/path/env/lib/python3.4/site-packages/django/utils/six.py", line 90, in __get__
result = self._resolve()
File "/home/user/path/env/lib/python3.4/site-packages/django/utils/six.py", line 113, in _resolve
return _import_module(self.mod)
File "/home/user/path/env/lib/python3.4/site-packages/django/utils/six.py", line 80, in _import_module
__import__(name)
File "/home/user/path/env/lib/python3.4/site-packages/django/http/__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
ImportError: cannot import name 'SimpleCookie'
as you can see the line,
from django.core.wsgi import get_wsgi_application
is failing
on the other hand, when i try it with the python interpreter, it imports correctly.
I have also verified that the same interpreter is being used by passenger by logging the variable
import sys
raise Exception(sys.executable)
Any ideas as to the cause of this?
I tried logging path, it displays the following
['/home/user/path/env/lib/python3.4/site-packages', '/home/user/path/env/lib/python3.4/site-packages/django', '/home/user/path/env/bin', '/home/user/path', '/usr/local/dh/passenger/helper-scripts', '/home/user/path/env/lib/python34.zip', '/home/user/path/env/lib/python3.4', '/home/user/path/env/lib/python3.4/plat-linux', '/home/user/path/env/lib/python3.4/lib-dynload', '/home/user/opt/python-3.4.2/lib/python3.4', '/home/user/opt/python-3.4.2/lib/python3.4/plat-linux', '/home/user/path/env/lib/python3.4/site-packages', '/home/user/path', '/home/user/path/git/package']
which seems fine to me
The instructions in dreamhost wiki works fine. You just need to remove the extra django path in your wsgi config file. It should look like this:
...
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/projectname') #You must add your project here
sys.path.insert(0,cwd+'/env/bin')
sys.path.insert(0,cwd+'/env/lib/python2.7/site-packages')
...
not like this:
...
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/projectname') #You must add your project here
sys.path.insert(0,cwd+'/env/lib/python2.7/site-packages/django')
sys.path.insert(0,cwd+'/env/bin')
sys.path.insert(0,cwd+'/env/lib/python2.7/site-packages')
...
I ran into a same problem and the following solution works for me.
I have Django 1.7 with Python 3.4, using Eclipse with PyDev as my IDE.
My solution is related to this thread: Import Python module fails (http.cookies)
What I did:
In Eclipse, go to tab Project/Properties
Select side-tab PyDev - PYTHONPATH
Select External Libraries
There should be a path which looks like /.../lib/pythonX.Y/site-packages/django. Remove it.
(I was using the venv package to create my virtual environment. Your path may differ.)
Run the project and see if it works.
Comment: I think this is indeed a very weird problem... Something to do with the PyDev - DjangoProject setup with Python3, possibly. Let me know if this helps.

Django-registration compatibility issue with django 1.7

I've been using [django-registration] (https://bitbucket.org/ubernostrum/django-registration) and now I have started using django 1.7b1 and here is the error I am getting the error copied below. It is being raised from django-registration in models.py:
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
and it seems it is being raised because get_user_model() is being called before the app registry is ready. I am not sure if this a compatibility issue or not, if yes is there a simple workaround for this? and if not can you help me identify what I am doing wrong?
RuntimeError: App registry isn't ready yet.
File "/Users/nima/pe-dev/manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/core/management/__init__.py", line 427, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/core/management/__init__.py", line 391, in execute
django.setup()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 106, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/config.py", line 190, 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 "/Library/Python/2.7/site-packages/registration/models.py", line 15, in <module>
User = get_user_model()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/contrib/auth/__init__.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 187, in get_model
self.check_ready()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 119, in check_ready
raise RuntimeError("App registry isn't ready yet.")
Don't use the django-registration available from PyPI. It does not support Django 1.7 and it appears it never will. The repo maintainer has abdicated and the project appears unmaintained.
There is a maintenance fork available on Github which has worked well for me with Django 1.7:
https://github.com/macropin/django-registration
It's available from PyPI as django-registration-redux.
https://pypi.python.org/pypi/django-registration-redux/
You can install using pip:
pip install django-registration-redux
This note addresses your problem.
I think the preferred way to import User is:
from django.conf import settings
User = settings.AUTH_USER_MODEL
EDIT:
Looks like this problem has been noted but the project admin is being difficult about making the change. link. This is a bigger problem with the updates in Django 1.7.
I would say you could either: (1) fork the repo and make the change yourself, or (2) make the changes in your site packages folder after you pip install. The latter version won't work as well if you then push it to another server and install with requirements.txt. Note that if you do option 1 with requirements.txt, you'll want to point it to your repo rather than Django-registration.

ImportError: cannot import name MPTTModel

I did the steps at the tutorial " http://django-mptt.github.com/django-mptt/tutorial.html "
but it still give me the import error , I double check the code for the mptt and found the class MPTTMODEL exist 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
One thing you could try: Go to the console and type: python (to get the python console) and then enter: from mptt.models import MPTTModel
If this gives you an error than mptt is not correctly installed.
If you are using pip you could easily do: pip install django-mptt or you might try pip install django-mptt --upgrade to update your installation. It might be that your installation did not succeeded.
If you are not using pip or virtualenv I highly recommend it. The start is a bit tough, but it is worse to install it. 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 into is probably not accessible to python. Therefore add the path where mptt lives to your PYTHONPATH. See this thread how to do it.