views:

283

answers:

3

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.

+2  A: 

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

Mark
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
Verrtex
Search in your centos repository using the yum search functionality.yum search pysqliteI get:python-sqlite.i386 1.1.7-1.2.1 installedMatched from:http://pysqlite.org/In my system there is a module called sqlite3
whatnick
When the library was included in Python it was for sqlite3 and renamed to sqlite3 I doubt you need the older sqlite2
Mark
But I also cannot import sqlite3 (I add some details to my main question).
Verrtex
How was python installed - I would expect all the libraries etc to be in /usr/ or /opt not your home directory
Mark
A: 

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.

ΤΖΩΤΖΙΟΥ
When I use yum "install python-sqlite" I get:You need to be root to perform this command.Can I instal sqlite without root privileges?
Verrtex
Generally, not. So, if you can use sudo on that machine, you should do `sudo yum install python-sqlite` and enter your password, or you should ask the system administrator to do that for you.
ΤΖΩΤΖΙΟΥ
+2  A: 

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

tarasm