Question

I am trying to install pysqlite and have troubles with that. I found out that the most probable reason of that is missing sqlite headers and I have to install them. My platform: CentOS release 5.3 (Final). I have Python-2.6.2.

I also found out that I need .rpm files. As far as I have them I execute:

rpm -i sqlite3-devel-3.n.n.n.rpm

and everything should be fine.

However, I do not know where to find sqlite3-devel-3.n.n.n.rpm file. Should it already be on my system? I could not locate it with "locate sqlite3-devel-3". Should I download this file? If yes where I can find it and which version should I use? I mean, the .rpm file should be, probably, consistent with the version of sqlite that I have on my computer? If it is the case, how can I find out the version of my sqlite?

If I type "from pysqlite2 import dbapi2 as sqlite" I get:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pysqlite2

"yum search pysqlite" gives me the following:

Loaded plugins: fastestmirror
Excluding Packages in global exclude
list Finished
==== Matched: pysqlite ==== python-sqlite.x86_64 : Python bindings
for sqlite.

By the way, I have the following directory: /home/myname/opt/lib/python2.6/sqlite3 and there I have the following files:

dbapi2.py  dbapi2.pyc  dbapi2.pyo 
dump.py  dump.pyc  dump.pyo 
__init__.py  __init__.pyc  __init__.pyo  test

If I type "import unittest" and then "import sqlite3 as sqlite" I get:

Traceback (most recent call last):  
File "<stdin>", line 1, in <module>  
File "/home/myname/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *   File "/home/myname/opt/lib/python2.6/sqlite3/dbapi2.py",
line 27, in <module>
    from _sqlite3 import * ImportError: No module named _sqlite3

Thank you in advance.

Was it helpful?

Solution

You can use buildout to create localized version of your project. This will install all necessary packages without having sudo access to the server.

To give it try, do the following:

mkdir tmp
cd tmp
wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
python bootstrap.py init
vim buildout.cfg

edit buildout.cfg and replace it with following:

[buildout]
parts = sqlite 

[sqlite]
recipe = zc.recipe.egg
eggs = pysqlite
interpreter = mypython

Now, run ./bin/buildout to rebuild the project. This will download all of the necessary packages and create a new interpreter for you that you can use test that you can access sqlite.

./bin/buildout
./bin/mypython
>>> import sqlite3

This gives you a controlled environment that you can use to develop inside of. To learn more about buildout, you can watch videos from pycon 2009 on Setuptools, Distutils and Buildout.

Eggs and Buildout Deployment in Python - Part 1

Eggs and Buildout Deployment in Python - Part 2

Eggs and Buildout Deployment in Python - Part 3

Good luck

OTHER TIPS

Python 2.6 (and some earlier) include sqlite Python org library ref so you should not need to do this. Just import it and run

Typically, you should install the python sqlite module through yum, something like:

yum install python-sqlite

and then edit your code changing sqlite2 references to sqlite3.

By the way, whenever you read directions to install sqlite3-devel-3.n.n.n.rpm, the n parts are not literal; they're supposed to be replaced with numbers specifying a version of the rpm package.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top