【问题标题】:How to import sqlite3 in my python3.4 successfully?如何在我的 python3.4 中成功导入 sqlite3?
【发布时间】:2014-12-14 14:56:57
【问题描述】:

我的debian7里面有两个python版本,一个是python2.7系统默认版本,一个是python3.4编译成这样安装的。

 apt-get update
 apt-get upgrade
 apt-get install build-essential
 wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz
 tar -zxvf Python-3.4.0.tgz
 cd Python-3.4.0
 mkdir /usr/local/python3.4
 ./configure --prefix=/usr/local/python3.4
 make
 make install
 ln -s /usr/local/python3.4/bin/python3.4   /usr/bin/python3.4
 ln -s /usr/local/python3.4/bin/pip3.4   /usr/bin/pip3.4

我已经在我的 debian 上以这种方式安装了 sqlite。

sudo apt-get install sqlite3 libsqlite3-dev 

在python2.7中

root@rebuild:~# python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3

在python3.4中

root@rebuild:~# python3.4
Python 3.4.0 (default, Nov 27 2014, 13:54:17)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python3.4/lib/python3.4/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/python3.4/lib/python3.4/sqlite3/dbapi2.py", line 26, in <module>
    from _sqlite3 import *
ImportError: No module named '_sqlite3'

如何在 python3.4 中成功导入 sqlite3?

【问题讨论】:

  • 您期待什么?如果您通过包管理器安装sqlite3,它将仅针对以相同方式安装的 Python 安装进行编译。你试过./configure --with-sqlite之类的吗?
  • 我可以在 python2.7 中导入 sqlite3,如何在我的 python3.4 中导入它?
  • 为电影人考虑。 apt-get install sqlite3 libsqlite3-dev 并重新编译以使用 ./configure --prefix=/usr/local/python3.4 --with-sqlite 安装 python

标签: sqlite python-3.4


【解决方案1】:

从提供的信息和顺序显示,您似乎在安装 sqlite-dev 软件包之前从源代码安装了 python 3.4。如果你仔细观察 python 3.4 的安装,你会注意到它没有构建任何数量的模块(其中之一是 _sqlite3)。

解决方案:既然 sqlite3 dev 可用,请重新安装 3.4。

【讨论】:

    【解决方案2】:

    我对这个问题也有同样的困扰,这个流程在 oracel-linux/python3 中成功

    1.下载安装sqlite3

    $ tar sqlite-autoconf-3180000.tar.gz  
    $ cd sqlite-autoconf-3180000  
    $./configure --prefix=/usr/local/sqlite3 && make && make install
    

    2.导出 LD_LIBRARY_PATH

    $ export LD_LIBRARY_PATH=/usr/local/lib
    

    3.下载安装python3.6

    $ tar Python-3.6.0.tar.xz  
    $ cd Python-3.6.0  
    $ ./configure && make && make install  
    

    【讨论】:

    • 这个解决方案也对我有用。在尝试更新到最新版本的 sqlite3 之前,我已经安装了 python。所以我编译了它,然后确保在我的 virtualenv 活动文件中运行导出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多