我正在尝试使用python 2.6.4运行python脚本。主机公司安装了2.4,所以我在类似的服务器上编译了我自己的2.6.4,然后将文件移到〜/ opt / python中。那部分似乎工作正常。
无论如何,当我运行下面的脚本时,我收到了ImportError: No module named _sqlite3
,我不知道该怎么做才能解决这个问题。
大多数在线主题都提到sqlite / sqlite3包含在python 2.6中 - 所以我不确定为什么这不起作用。
-jailshell-3.2$ ./pyDropboxValues.py Traceback (most recent call last): File "./pyDropboxValues.py", line 21, in import sqlite3 File "/home/myAccount/opt/lib/python2.6/sqlite3/__init__.py", line 24, in from dbapi2 import * File "/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: No module named _sqlite3
我认为我已将所有内容设置为目录结构。
-jailshell-3.2$ find `pwd` -type d /home/myAccount/opt /home/myAccount/opt/bin /home/myAccount/opt/include /home/myAccount/opt/include/python2.6 /home/myAccount/opt/lib /home/myAccount/opt/lib/python2.6 /home/myAccount/opt/lib/python2.6/distutils /home/myAccount/opt/lib/python2.6/distutils/command /home/myAccount/opt/lib/python2.6/distutils/tests /home/myAccount/opt/lib/python2.6/compiler /home/myAccount/opt/lib/python2.6/test /home/myAccount/opt/lib/python2.6/test/decimaltestdata /home/myAccount/opt/lib/python2.6/config /home/myAccount/opt/lib/python2.6/json /home/myAccount/opt/lib/python2.6/json/tests /home/myAccount/opt/lib/python2.6/email /home/myAccount/opt/lib/python2.6/email/test /home/myAccount/opt/lib/python2.6/email/test/data /home/myAccount/opt/lib/python2.6/email/mime /home/myAccount/opt/lib/python2.6/lib2to3 /home/myAccount/opt/lib/python2.6/lib2to3/pgen2 /home/myAccount/opt/lib/python2.6/lib2to3/fixes /home/myAccount/opt/lib/python2.6/lib2to3/tests /home/myAccount/opt/lib/python2.6/xml /home/myAccount/opt/lib/python2.6/xml/parsers /home/myAccount/opt/lib/python2.6/xml/sax /home/myAccount/opt/lib/python2.6/xml/etree /home/myAccount/opt/lib/python2.6/xml/dom /home/myAccount/opt/lib/python2.6/site-packages /home/myAccount/opt/lib/python2.6/logging /home/myAccount/opt/lib/python2.6/lib-dynload /home/myAccount/opt/lib/python2.6/sqlite3 /home/myAccount/opt/lib/python2.6/sqlite3/test /home/myAccount/opt/lib/python2.6/encodings /home/myAccount/opt/lib/python2.6/wsgiref /home/myAccount/opt/lib/python2.6/multiprocessing /home/myAccount/opt/lib/python2.6/multiprocessing/dummy /home/myAccount/opt/lib/python2.6/curses /home/myAccount/opt/lib/python2.6/bsddb /home/myAccount/opt/lib/python2.6/bsddb/test /home/myAccount/opt/lib/python2.6/idlelib /home/myAccount/opt/lib/python2.6/idlelib/Icons /home/myAccount/opt/lib/python2.6/tmp /home/myAccount/opt/lib/python2.6/lib-old /home/myAccount/opt/lib/python2.6/lib-tk /home/myAccount/opt/lib/python2.6/hotshot /home/myAccount/opt/lib/python2.6/plat-linux2 /home/myAccount/opt/lib/python2.6/ctypes /home/myAccount/opt/lib/python2.6/ctypes/test /home/myAccount/opt/lib/python2.6/ctypes/macholib /home/myAccount/opt/share /home/myAccount/opt/share/man /home/myAccount/opt/share/man/man1
最后是sqlite3目录的内容:
-jailshell-3.2$ find `pwd` /home/myAccount/opt/lib/python2.6/sqlite3 /home/myAccount/opt/lib/python2.6/sqlite3/__init__.pyo /home/myAccount/opt/lib/python2.6/sqlite3/dump.pyc /home/myAccount/opt/lib/python2.6/sqlite3/__init__.pyc /home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.pyo /home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.pyc /home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.py /home/myAccount/opt/lib/python2.6/sqlite3/dump.pyo /home/myAccount/opt/lib/python2.6/sqlite3/__init__.py /home/myAccount/opt/lib/python2.6/sqlite3/dump.py
我觉得我需要在sqlite3
目录中添加一些东西 - 也许是sqlite3.so?但我不知道从哪里来。
我在这里做错了什么?请记住,我正在使用共享主机,这意味着在另一台服务器上安装/编译,然后复制文件。谢谢! :)
更新 只是想确认@samplebias的答案确实很好。我需要在我编译的机器上安装dev包,以便在sqlite3.so和相关文件中添加它。还发现答案中的链接非常有帮助。谢谢@samplebias!
答案 0 :(得分:0)
一般来说,首先要问的是你的主人。我似乎有点奇怪,SQLite没有安装(或正确安装)。因此,如果你问他们,他们很可能会很快解决它。
答案 1 :(得分:0)
对于python 2.4,您需要sqlite和绑定,pysqlite 2或aspw
答案 2 :(得分:0)
sqlite
文件夹中列出的所有文件都不是_sqlite3.pyd
Python共享库。你确定在编译Python时编译它吗?构建日志说什么?我认为需要传递configure
标志。
或者,只需安装pysqlite
即可答案 3 :(得分:0)
Python的构建系统uses a setup.py file to compile all of the native extensions,包括sqlite3。它搜索sqlite3 include和library dirs的常见操作系统路径。如果没有安装sqlite3开发包,Python将跳过编译_sqlite3.so
扩展,但仍会安装sqlite3
包的纯Python部分。
在编译Python时和运行时需要安装操作系统的sqlite3开发包:Centos上的sqlite3-devel
,在Ubuntu上都是libsqlite3-0
和libsqlite3-dev
。
以下是我的Ubuntu系统上_sqlite3.so
扩展链接的示例:
% ldd /usr/lib/python2.6/lib-dynload/_sqlite3.so | grep sqlite3
libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x00007f29ef3be000)
% dpkg -S /usr/lib/libsqlite3.so.0
libsqlite3-0: /usr/lib/libsqlite3.so.0