execute_from_command_line (sys.argv) I am new to Python and Django. I am trying to install Djang...">

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

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

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

      

Python is correctly installed. so when i do /root/python3/bin/python3.4

i get Python version 3.4.2 so i created soft link ->ln -s /root/python3/bin/python3.4 python3

Now I have created a virtualenv via

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

      

then i installed DJango:

pip install Django==1.9

      

Django installed successfully

Created the myproj project:

django-admin startproject myproj

      

successfully created myproj project:

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 the command python manage.py runserver

, I get the 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 have tried all solutions provided in all discussions on stackoverflow.

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 haven't added any environment variables like PYTHONPATH or PATH. I must do it. If so, let me know what to install and how to install.

Requesting all of you to help resolve this error so I can get started with Django. It's almost 3-4 days I've been fighting.

+3


source to share


1 answer


In a similar bug report , it looks like the problem was with an older version of sqlite3.

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



Note that Django 1.9 is the end of life and no longer receives security fixes. I suggest you upgrade to the new 1.11 LTS (or maybe upgrade to the previous 1.8 LTS if you can't upgrade).

+3


source







All Articles