Skip to main content
 首页 » 编程设计

Python3 无法识别 sqlite

2025年05月04日9linjiqin

我在 linux 上安装了 python3。在 python 解释器中,我尝试了

import sqlite3 

得到了

ImportError: No module named '_sqlite3' 

所以我安装了sqlite

sudo apt-get install libsqlite-dev 

然后根据README文件中的说明重新编译python:

cd ~/Python-3.4.2; 
./configure; 
make; 
make test; 

在测试期间有一个错误说

[ 97/389] test_sqlite 
test_sqlite skipped -- No module named '_sqlite3' 

然后当我完成安装并尝试运行相同的 python 代码时,我仍然遇到相同的 ImportError。我做错了什么?

---编辑---

我试过了

pip install pysqlite 

得到这个错误,这似乎是 Python2.7 和 Python3.4 之间的问题:

Downloading/unpacking pysqlite 
  Downloading pysqlite-2.6.3.tar.gz (76kB): 76kB downloaded 
  Running setup.py (path:/tmp/pip_build_plat/pysqlite/setup.py) egg_info for package pysqlite 
    Traceback (most recent call last): 
      File "<string>", line 17, in <module> 
      File "/tmp/pip_build_plat/pysqlite/setup.py", line 85 
        print "Is sphinx installed? If not, try 'sudo easy_install sphinx'." 
                                                                           ^ 
    SyntaxError: Missing parentheses in call to 'print' 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
 
  File "<string>", line 17, in <module> 
 
  File "/tmp/pip_build_plat/pysqlite/setup.py", line 85 
 
    print "Is sphinx installed? If not, try 'sudo easy_install sphinx'." 
 
                                                                       ^ 
 
SyntaxError: Missing parentheses in call to 'print' 
 
---------------------------------------- 
Cleaning up... 
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_plat/pysqlite 
Storing debug log for failure in /home/plat/.pip/pip.log 

请您参考如下方法:

安装 libsqlite-dev 后你应该安装 pysqlite

pip install pysqlite