1

I'm trying to use sqlite with python via the import function, but it looks that python can't find sqlite.

My sys.path contains the following:

['', '/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']

But sqlite is listed in usr/lib.

Edit:
As suggested, I tried import sqlite3, but python returns this error:

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

How do I load sqlite?

2 Answers 2

1

There is no need to add anything to your module search path; the SQLite module comes with the Python standard library. However, you misspelled the name of the module, it is called sqlite3 (note the 3 on the end):

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>

If you get errors still, your homebrew installation is broken; you probably ran into this bug. Run:

brew rm sqlite python
brew install python

to repair.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks - Tried that, but got an error message. Updated the post with the error message.
@mikebmassey: Right, that is a homebrew bug, instructions to fix included.
0

sqlite3 is the name of the python module which provides an interface between Python and the sqlite database engine. sqlite is the name of the underlying database engine.

So (as Martijn Pieters already pointed out) try:

import sqlite3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.