python經(jīng)常在某些環(huán)境安裝的時(shí)候會(huì)出現(xiàn),這個(gè)錯(cuò)誤:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python3.6/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/python3.6/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
可能的原因是因?yàn)榘惭bpython的時(shí)候沒有找到sqlite3.so的庫巩割。
簡單的解決方式:
# 安裝sqlite相關(guān)的全部,可能并不需要全部,為了簡單直接用*號(hào)代替了
yum install sqlite*
然后重新編譯python或者重新安裝python
如果這種方式解決不了闹瞧,建議通過編譯安裝sqlite3,下載地址
./configure --prefix=/usr/local/sqlite3
make && make install
然后打開python安裝源碼的setup.py修改如下:
sqlite_inc_paths = [ '/usr/include',
'/usr/local/sqlite3/include', #增加該部分內(nèi)容
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
重新編譯安裝展辞。
上面的方法我自己在centos6.5奥邮、python3.6的環(huán)境依舊沒解決問題。最后我是這樣解決的:
#手動(dòng)安裝sqlite3 完成的時(shí)候會(huì)有這么一段提示:
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
這段內(nèi)容顯示了sqlite3的安裝路徑:/usr/local/lib
罗珍。
特別注意add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
sqlite建議添加環(huán)境變量洽腺。
export LD_LIBRARY_PATH=/usr/local/lib
設(shè)置一個(gè)環(huán)境變量,然后重新編譯python3安裝就能夠成功了覆旱。