Django Runserver错误,新安装,Django的首次用户

时间:2019-05-03 06:24:04

标签: python django linux conda

因此,我决定学习Django,如果我无法使其正常运行,这将是一个挑战。

跑步 Python 3.7.1(默认,2018年12月14日,19:28:38) [GCC 7.3.0] :: Linux上的Anaconda,Inc。

(基本)runout @ runout:〜$ python -m django --version 2.2.1

我正在关注djangoproject.com的初学者教程

代码的第一行是创建一个网站,我做了...

django-admin startproject mysite

第二行代码是我遇到问题的地方。

python manage.py runserver

我的错误如下:

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/runout/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/runout/anaconda3/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
    raise _exception[0](_exception[1]).with_traceback(_exception[2])
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/runout/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
    value.contribute_to_class(cls, name)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/models/options.py", line 204, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
    return import_module('%s.base' % backend_name)
  File "/home/runout/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 28, in <module>
    from .introspection import DatabaseIntrospection            # isort:skip
  File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/backends/sqlite3/introspection.py", line 4, in <module>
    import sqlparse
ModuleNotFoundError: No module named 'sqlparse'

我对Django一无所知,我很高兴学习。我一直在网上和SO处寻找解决此问题的方法,但无济于事。谁能让我起床并跑步?

2 个答案:

答案 0 :(得分:1)

显然缺少python软件包。您可以这样安装它:

pip install sqlparse

答案 1 :(得分:0)

您使用的是Linux,因此请输入以下命令安装“ sqlparse”: pip3 install sqlparse。另外,您应该使用python3来调用python,以免与python2混淆。