我想使用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