Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)

Tags:

python

django

I am new to Python and Django. I am trying to install Django on Linux. Python version currently available on the server is Python 2.4.3 I installed Python 3.4.2 following the below steps:

wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
tar -xvzf Python-3.4.2.tgz
cd Python-3.4.2
./configure --prefix=/root/python3
make
make install

The python correctly got installed. so when I do /root/python3/bin/python3.4 I get Python version 3.4.2 so i created a soft link -> ln -s /root/python3/bin/python3.4 python3

Now i created a virtualenv through

/root/python3/bin/pyvenv-3.4 venv3.4
source venv3.4/bin/activate

then i installed DJango:

pip install Django==1.9

Django got successfully installed

Created the project myproj:

django-admin startproject myproj

myproj project successfully created:

cd myproj

now when i do python manage.py migrate i get error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 89, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/loader.py", line 176, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 56, in ensure_schema
    with self.connection.schema_editor() as editor:
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/backends/sqlite3/schema.py", line 25, in __enter__
    self._initial_pragma_fk = c.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable

When i execute command python manage.py runserver i get error:

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fc0df5e7f28>
Traceback (most recent call last):
  File "/root/venv3.4/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    self.check_migrations()
  File "/root/venv3.4/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 163, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/loader.py", line 176, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 56, in ensure_schema
    with self.connection.schema_editor() as editor:
  File "/root/venv3.4/lib/python3.4/site-packages/django/db/backends/sqlite3/schema.py", line 25, in __enter__
    self._initial_pragma_fk = c.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable

I tried all the solutions provided in all stackoverflow discussions.

settings.py file

"""
Django settings for myproj project.

Generated by 'django-admin startproject' using Django 1.9.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'qg#8o8)e*or5o#g+pxp3_&9r*=i2b*k59wjis=!*5a1&b6^^_='

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'myproj.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'myproj.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

manage.py file

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproj.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

Django version -> 1.9

I have not added any environment variable like PYTHONPATH or PATH. DO i need to do it. If yes please let me know what to set and how to set.

Requesting you all to please help in resolving this error so that i can start working on Django. Its almost more than 3-4 days i am struggling.

like image 269
Nishant Nikhil Avatar asked Jun 05 '17 10:06

Nishant Nikhil


1 Answers

On a similar bug report, it looks like the problem was an old version of sqlite3.

Django only supports the latest point release of Python, so if you want to use Python 3.4, I suggest that you install 3.4.6 instead of 3.4.2.

Note that Django 1.9 is end of life and does not receive security fixes any more. I suggest you upgrade to the new 1.11 LTS (or possibly downgrade to the previous 1.8 LTS if you are not able to upgrade).

like image 99
Alasdair Avatar answered Sep 30 '22 17:09

Alasdair