0

I use Django 1.9 after updating of Django 1.8, and when i type command

django-admin runserver

I got this one error:

Traceback (most recent call last):
  File "/usr/local/bin/django-admin", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
    working_set = WorkingSet._build_master()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 446, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 459, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Django==1.8.3

And then I try to type this one command:

django-admin.py runserver

I got this one error:

Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 195, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 39, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 16, in <module>
    from django.db.migrations.executor import MigrationExecutor
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 7, in <module>
    from .loader import MigrationLoader
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 10, in <module>
    from django.db.migrations.recorder import MigrationRecorder
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 12, in <module>
    class MigrationRecorder(object):
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 26, in MigrationRecorder
    class Migration(models.Model):
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 27, in Migration
    app = models.CharField(max_length=255)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1072, in __init__
    super(CharField, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 166, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I try uninstall and install Django. But i still have this errors. Hope somebody can help me with it. Thanks

Zagorodniy Olexiy
  • 2,132
  • 3
  • 22
  • 47
  • Did you use both `pip` and `easy_install` to manage your packages? If yes, then answer to [this question](http://stackoverflow.com/questions/6200056/pip-broke-how-to-fix-distributionnotfound-error) may be of some help. – rafalmp Jul 27 '16 at 14:01

2 Answers2

2

You shouldn't normally use django-admin, except when you do django-admin startproject.

After you have created the project, it is easier to use manage.py to run the dev server, because it takes care of setting the path and settings module for you.

./manage.py runserver

See the docs for more information.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
0

Maybe you used another python version? It is python 2.7 now, and it seems you don't installed django properly for python2.7. You can try

python3 manage.py runserver

for using python3 in ubuntu (it is installed by default and accessibler with python3), or try to define how to run it with another python version.

birdy90
  • 134
  • 1
  • 2
  • 14
  • When i try to `python3 manage.py run server`, i got `ImportError: No module named 'django'` – Zagorodniy Olexiy Jul 27 '16 at 13:32
  • Well, i failed. Then you can try to determine if it is installed coorectly, and first of all check your env variables. There's one close question: http://stackoverflow.com/questions/8712371/pkg-resources-distributionnotfound-django-1-3-1-while-crating-a-new-project-in. Try it and tell if it solve you problem – birdy90 Jul 27 '16 at 13:42