1

我正在尝试sqlite通过该函数与 python一起使用import,但看起来 python 找不到sqlite.

我的 sys.path 包含以下内容:

['', '/usr/local/share/python', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/distribute-0.6.26-py2.7.egg', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/usr/local/Cellar/python/2.7.3/lib/python27.zip', '/usr/local/Cellar/python/2.7.3/lib/python2.7', '/usr/local/Cellar/python/2.7.3/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.3/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.3/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/IPython/extensions']

sqlite列在usr/lib.

编辑:
正如建议的那样,我试过import sqlite3了,但是 python 返回了这个错误:

dlopen(/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-dynload/_sqlite3.so, 2): Library not loaded: /usr/local/lib/libsqlite3.0.8.6.dylib
  Referenced from: /usr/local/Cellar/python/2.7.3/lib/python2.7/lib-dynload/_sqlite3.so
  Reason: image not found

我该如何加载sqlite

4

2 回答 2

1

无需在模块搜索路径中添加任何内容;SQLite 模块随 Python 标准库一起提供。但是,您拼错了模块的名称,它被称为sqlite3(注意3末尾的):

Python 2.7.3 (default, Oct 22 2012, 06:12:32) 
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.connect(':memory:')
<sqlite3.Connection object at 0x105354200>

如果仍然出现错误,则说明您的自制软件安装已损坏;你可能遇到了这个错误。跑:

brew rm sqlite python
brew install python

修理。

于 2013-05-26T14:26:03.943 回答
0

sqlite3是 python 模块的名称,它提供了 Python 和 sqlite 数据库引擎之间的接口。sqlite是底层数据库引擎的名称。

所以(正如 Martijn Pieters 已经指出的那样)尝试:

import sqlite3
于 2013-05-26T14:42:30.237 回答