龙空技术网

CentOS 安装Django以及运行报错“No module named _sqlite3”

dwolf79 262

前言:

现时姐妹们对“centosgosqlite3”大致比较注重,你们都想要分析一些“centosgosqlite3”的相关知识。那么小编同时在网上收集了一些关于“centosgosqlite3””的相关文章,希望大家能喜欢,我们快快来了解一下吧!

前言

Django 是Python常用的web框架,这里使用CentOS 6.X 系列进行安装,安装完成后,在运行使用时出现错误,后面进行说明。

安装与运行

由于Django目前只支持python 2.7以上的版本,这里使用的CentOS 6.X系列默认是python 2.6版本。进行python版本的升级操作。

安装命令如下:

[root@private django_dir]# python --version

Python 2.7.13

[root@private django_dir]# pip install django

Collecting django

Using cached Django-1.11.6-py2.py3-none-any.whl

Requirement already satisfied: pytz in /usr/local/lib/python2.7/site-packages (from django)

Installing collected packages: django

Successfully installed django-1.11.6

[root@private django_dir]#

安装完成Django后,进行Django的使用,创建新项目:

[root@private django_dir]# django-admin startproject myblog

[root@private django_dir]# ls -d myblog/

myblog/

[root@private django_dir]# ll myblog/*

-rwxr-xr-x 1 root root 804 Oct 22 14:58 myblog/manage.py

myblog/myblog:

total 12

-rw-r--r-- 1 root root 0 Oct 22 14:58 __init__.py

-rw-r--r-- 1 root root 3096 Oct 22 14:58 settings.py

-rw-r--r-- 1 root root 763 Oct 22 14:58 urls.py

-rw-r--r-- 1 root root 390 Oct 22 14:58 wsgi.py

[root@private django_dir]#

在运行'python manage.py runserver'时,出现如下报错:

[root@private blog]# python manage.py

Traceback (most recent call last):

File "manage.py", line 22, in <module>

execute_from_command_line(sys.argv)

File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line

utility.execute()

File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute

django.setup()

File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup

apps.populate(settings.INSTALLED_APPS)

File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate

app_config.import_models()

File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models

self.models_module = import_module(models_module_name)

File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module

__import__(name)

File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>

from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager

File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>

class AbstractBaseUser(models.Model):

File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__

new_class.add_to_class('_meta', Options(meta, app_label))

File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 325, in add_to_class

value.contribute_to_class(cls, name)

File "/usr/local/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class

self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())

File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__

return getattr(connections[DEFAULT_DB_ALIAS], item)

File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__

backend = load_backend(db['ENGINE'])

File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend

return import_module('%s.base' % backend_name)

File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module

__import__(name)

File "/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 35, in <module>

raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)

django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

该报错是由于Python的依赖包 sqlite-devel 导致的。修复方案为:

yum -y install sqlite-devel

然后重新进行./congure 和 make 、make install Python版本。再进行运行就可以了。

标签: #centosgosqlite3