Liam Chaney
Liam Chaney

Reputation: 13

Django-admin command error Unable to start project

I am trying to start a project in a virtual environment using the django-admin command.

pip freeze output: django==2.0.7 (part of the tutorial same happens w/ update package) pytz==2021.3

The error I get for django-admin check is

Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\Scripts\django-admin.exe\__main__.py", line 7, in <module>
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\commands\check.py", line 63, in handle
    self.check(
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 438, in check
    all_issues = checks.run_checks(
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\checks\registry.py", line 77, in run_checks    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\checks\templates.py", line 29, in check_string_if_invalid_is_string
    for conf in settings.TEMPLATES:
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\conf\__init__.py", line 84, in __getattr__
    self._setup(name)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\conf\__init__.py", line 65, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This just started after I had deleted my old project to start again using a comprehensive tutorial. I have tried deleting the virtualenv via clearing the \dev\django\ folder, and restarting.

I've seen other questions answered by editing the settings.py or manage.py file, but I don't have those at this stage.

Thanks.

Update#1: Tried repairing python installs, and doing the same thing on another user. Still get the error. I have noticed that launching the django-admin.py and .exe only difference is that the .exe goes through runpy.py first

I made a mistake with the errors this is the error for django-admin startproject

raceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\users\liam\documents\dev\Django\Scripts\django-admin.exe\__main__.py", line 7, in <module>
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\commands\startproject.py", line 20, in handle
    super().handle('project', project_name, target, **options)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\templates.py", line 117, in handle
    django.setup()
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\__init__.py", line 16, in setup
    from django.urls import set_script_prefix
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\urls\__init__.py", line 1, in <module>
    from .base import (
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\urls\base.py", line 8, in <module>
    from .exceptions import NoReverseMatch, Resolver404
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\urls\exceptions.py", line 1, in <module>
    from django.http import Http404
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\http\__init__.py", line 5, in <module>
    from django.http.response import (
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\http\response.py", line 13, in <module>
    from django.core.serializers.json import DjangoJSONEncoder
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\serializers\__init__.py", line 23, in <module>
    from django.core.serializers.base import SerializerDoesNotExist
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\serializers\base.py", line 6, in <module>
    from django.db import models
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\__init__.py", line 3, in <module>
    from django.db.models.aggregates import *  # NOQA
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\aggregates.py", line 5, in <module>
    from django.db.models.expressions import Case, Func, Star, When
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\expressions.py", line 486, in <module>
    class TemporalSubtraction(CombinedExpression):
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\expressions.py", line 487, in TemporalSubtraction
    output_field = fields.DurationField()
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\fields\__init__.py", line 155, in __init__
    if isinstance(choices, collections.Iterator):
AttributeError: module 'collections' has no attribute 'Iterator'

Update#2 I updated to Django 3.0.0 Pip freeze output:

asgiref==3.4.1
Django==3.0
pytz==2021.3
sqlparse==0.4.2

It works I can use the django-admin startproject. I'm still weirded out that it worked with 2.0.7, and didn't work before with an updated package.

Upvotes: 0

Views: 1324

Answers (4)

saud
saud

Reputation: 1

django-admin startproject logisticontrading django-admin : The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again. At line:1 char:1

  • django-admin startproject logisticontrading
  •   + CategoryInfo          : ObjectNotFound: (django-admin:String) [], CommandNotFoun  
    dException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

Upvotes: 0

bagus Setyawan
bagus Setyawan

Reputation: 11

I have trouble somethink like you.. And i resolve by using this command :

python -m pip install -U Django

this is mean we cant upgrade your our jdango version..

And you cant try aganin to make new project with command :

django-admin startproject yournameproject

goodluck

Upvotes: 1

Swift
Swift

Reputation: 1711

Try a different method of creating your project and see if that works?

python -m django <command>

I have also double checked and youre using a really old version of django and i dont recommend.

Perhaps try upgrading to a later version of django and retry the original command aswell?

Upvotes: 0

Swift
Swift

Reputation: 1711

In you settings.py file there should be a variable called TEMPLATES

When starting a fresh project it should look something like this:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

From the error message you have shown us, im guessing this may be missing or misconfigured somehow.

Upvotes: 0

Related Questions