我想使用python 2.6.4运行python脚本。托管公司已安装2.4,所以我编译我自己的2.6.4在一个类似的服务器上,然后将文件转移到〜/ opt/python。那部分似乎工作正常。无论如何,当我运行下面的脚本,我得到ImportError: No module named _sqlite3
,我不知道该怎么做来解决这个问题。如何让sqlite在共享托管服务器上工作?
大多数线上线程提到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!
我建立的机器是ubuntu 64.我会用'apt-get install sqlite3 libsqlite3-dev'安装sqlite3(dev软件包)吗?在构建python时,是否有语法或者会自动包含它? – cwd 2011-05-17 14:19:19
是的,一旦你在构建主机上安装了sqlite3包,Python的'setup.py'就会找到它们并编译本地扩展。然后,您需要将相关库(包括sqlite3本身)复制到托管服务器,并确保共享链接程序可以找到它们(例如,您可能必须设置“LD_LIBRARY_PATH”)。我对其他类似问题的答案[显示如何提取Ubuntu软件包并在没有管理员权限的情况下使用它们](http://stackoverflow.com/questions/5976030/how-to-install-lxml-for-python-without-administative-版权上的Linux/5981037#5981037)。 – samplebias 2011-05-17 15:14:33