Django:<module> execute_from_command_line(sys.argv)中的文件“ manage.py”,第10行

Nis*_*hil 5 python django

我是Python和Django的新手。我正在尝试在Linux上安装Django。服务器上当前可用的Python版本是Python 2.4.3,我按照以下步骤安装了Python 3.4.2:

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
Run Code Online (Sandbox Code Playgroud)

正确安装了python。所以当我/root/python3/bin/python3.4得到Python版本3.4.2时,我创建了一个软链接->ln -s /root/python3/bin/python3.4 python3

现在我通过创建了一个virtualenv

/root/python3/bin/pyvenv-3.4 venv3.4
source venv3.4/bin/activate
Run Code Online (Sandbox Code Playgroud)

然后我安装了DJango:

pip install Django==1.9
Run Code Online (Sandbox Code Playgroud)

Django已成功安装

创建了项目myproj:

django-admin startproject myproj
Run Code Online (Sandbox Code Playgroud)

myproj项目成功创建:

cd myproj
Run Code Online (Sandbox Code Playgroud)

现在,当我做python manage.py migrate我得到错误:

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
Run Code Online (Sandbox Code Playgroud)

当我执行命令时python manage.py runserver出现错误:

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
Run Code Online (Sandbox Code Playgroud)

我尝试了所有stackoverflow讨论中提供的所有解决方案。

settings.py文件

"""
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/'
Run Code Online (Sandbox Code Playgroud)

manage.py文件

#!/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)
Run Code Online (Sandbox Code Playgroud)

Django版本-> 1.9

我没有添加任何环境变量,例如PYTHONPATH或PATH。我需要这样做吗?如果是,请让我知道要设置什么以及如何设置。

请大家帮助解决这个错误,以便我可以开始使用Django。我几乎要花费3-4天的时间。

Ala*_*air 5

类似的错误报告中,问题似乎是sqlite3的旧版本。

Django仅支持最新版本的Python,因此,如果要使用Python 3.4,建议您安装3.4.6而不是3.4.2。

请注意,Django 1.9已停产,并且不再接收安全修复程序。我建议您升级到新的1.11 LTS(如果无法升级,则可能降级到以前的1.8 LTS)。