django初体验之Error: No module named _sqlite

  安装好django之后,在bash shell中使用django-admin.py创建新项目,直接执行django-admin.py或django-admin而不带任何选项,则会列举出所有的选项。选项startproject用于创建一个新的项目。

[root@pwd]# django-admin.py startproject mysite
[root@pwd]# cd mysite
[root@mysite]# ls -l
-rwxr-xr-x. 1 root root  249 Dec 31 16:45 manage.py
drwxr-xr-x. 2 root root 4096 Dec 31 16:58 mysite
[root@mysite]# cd mysite
[root@mysite]# ls -l
-rw-r--r--. 1 root root    0 Dec 31 16:45 __init__.py
-rw-r--r--. 1 root root 3164 Dec 31 16:45 settings.py
-rw-r--r--. 1 root root  818 Dec 31 16:45 urls.py
-rw-r--r--. 1 root root  389 Dec 31 16:45 wsgi.py

下面准备runserver,给“manage.py”添加执行权限,然后执行“./manage.py runserver”,这时又遇到问题,traceback的结尾显示:

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

google之后得知需要安装pysqlite。访问https://pypi.python.org/simple/pysqlite/ 可以下载pysqlite的源代码

[root@tmp]# wget https://pypi.python.org/packages/source/p/pysqlite/pysqlite-2.8.1.tar.gz
[root@tmp]# tar -zxf pysqlite-2.8.1.tar.gz
[root@tmp]# cd pysqlite-2.8.1
[root@pysqlite-2.8.1]# python setup.py
 
 
 
 

按以上命令安装pysqlite之后收到如下报错:

building 'pysqlite2._sqlite' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -IPackage -Isqlite3 -Iwas -Inot -Ifound -Iin -Ithe -Ipkg-config -Isearch -Ipath. -IPerhaps -Iyou -Ishould -Iadd -Ithe -Idirectory -Icontaining -I`sqlite3.pc' -Ito -Ithe -IPKG_CONFIG_PATH -Ienvironment -Ivariable -INo -Ipackage -I'sqlite3' -Ifound -I/usr/local/include/python2.7 -c src/module.c -o build/temp.linux-x86_64-2.7/src/module.o
In file included from src/module.c:24:
src/connection.h:33:21: error: sqlite3.h: No such file or directory
In file included from src/module.c:24:
src/connection.h:38: error: expected specifier-qualifier-list before ‘sqlite3’
In file included from src/module.c:25:
src/statement.h:37: error: expected specifier-qualifier-list before ‘sqlite3’
src/module.c: In function ‘module_complete’:
src/module.c:101: warning: implicit declaration of function ‘sqlite3_complete’
src/module.c: In function ‘init_sqlite’:
src/module.c:400: warning: implicit declaration of function ‘sqlite3_libversion’
src/module.c:400: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast
/usr/local/include/python2.7/stringobject.h:63: note: expected ‘const char *’ but argument is of type ‘int’
error: command 'gcc' failed with exit status 1


真是奇了怪了,明明有gcc嘛,继续google,得知是缺少libffi-devel python-devel openssl-devel三个软件,(有的说是只缺少python-devel,我三个都yum了)

继续,还是同样报错,一怒之下,使用“yum -y install gcc*”把所有以gcc开头的软件包都装了,再次尝试,仍然报错。

冷静下来仔细往回看,发现若干“src/connection.h:33:21: error: sqlite3.h: No such file or directory”之类的消息,最后终于确定是缺少了“sqlite-devel”这个软件包。安装之后,再次尝试,终于build和install成功。

再次执行“./manage.py runserver”,仍然提示

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


突然想起前面安装了很多devel软件包,应该是需要重新编译Python,抱着试一试的想法重新编译安装了Python2.7,然后回来执行“./manage.py runserver”,终于成功!

[root@mysite]# ./manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

January 04, 2016 - 10:50:31
Django version 1.9, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.




 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值