Runserver Error (Exceptions) in Latest Django Dev Version with Python 3.3

427 views
Skip to first unread message

Noah Fang

unread,
Jan 2, 2014, 8:32:17 PM1/2/14
to django...@googlegroups.com
Django newbie here. I just checked out and installed the latest dev version as instructed and created a project, but when trying to "python manage.py runserver", it gives the following error message.

Anyone has any clue? Huge thanks!

$ python manage.py runserver
Traceback (most recent call last):
  File "/Users/noahark/Dev/django-trunk/django/apps/base.py", line 66, in create
    module = import_module(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/Users/noahark/Dev/django-trunk/django/contrib/admin/__init__.py", line 5, in <module>
    from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
  File "/Users/noahark/Dev/django-trunk/django/contrib/admin/options.py", line 31, in <module>
    from django.shortcuts import get_object_or_404
ImportError: bad magic number in 'django.shortcuts': b'\x03\xf3\r\n'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/noahark/Dev/django-trunk/django/apps/base.py", line 80, in create
    cls = getattr(mod, cls_name)
AttributeError: 'module' object has no attribute 'admin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/noahark/Dev/django-trunk/django/core/management/__init__.py", line 426, in execute_from_command_line
    utility.execute()
  File "/Users/noahark/Dev/django-trunk/django/core/management/__init__.py", line 389, in execute
    django.setup()
  File "/Users/noahark/Dev/django-trunk/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/noahark/Dev/django-trunk/django/apps/registry.py", line 81, in populate
    app_config = AppConfig.create(entry)
  File "/Users/noahark/Dev/django-trunk/django/apps/base.py", line 86, in create
    "cannot import name '%s' from '%s'" % (cls_name, mod_path))
ImportError: cannot import name 'admin' from 'django.contrib'

Russell Keith-Magee

unread,
Jan 2, 2014, 11:03:51 PM1/2/14
to Django Users
On Fri, Jan 3, 2014 at 9:32 AM, Noah Fang <noah...@gmail.com> wrote:
Django newbie here. I just checked out and installed the latest dev version as instructed and created a project, but when trying to "python manage.py runserver", it gives the following error message.

Anyone has any clue? Huge thanks!

$ python manage.py runserver
Traceback (most recent call last):
  File "/Users/noahark/Dev/django-trunk/django/apps/base.py", line 66, in create
    module = import_module(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/Users/noahark/Dev/django-trunk/django/contrib/admin/__init__.py", line 5, in <module>
    from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
  File "/Users/noahark/Dev/django-trunk/django/contrib/admin/options.py", line 31, in <module>
    from django.shortcuts import get_object_or_404
ImportError: bad magic number in 'django.shortcuts': b'\x03\xf3\r\n'

This error is a bit of a red flag -- it means that you've got mixed Python byte code versions. Somehow, you've generated byte code using one version of Python, and you're then running the code using a different version of Python.

Unfortunately, I have *no* idea how you might have caused this problem. It looks like you're running on a Mac, so it's possible that the system is getting confused over whether system python is Python 3 or Python 2 -- you're invoking "python manage.py runserver" at the command line and getting Python 3, but if some quirk of your environment is causing Python 2 to be the system default somewhere, you will get problems.

My suggestion here is to make sure you're running your code in a virtualenv [1] -- that will make sure that the "local" Python is always clear. Using virtualenv is good practice anyway for Python development, because it isolates the dependencies of each project from each other. 


Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages