How to build the pysqlite? Where to find the "sqlite3.h"?

K

Kurda Yon

Hi,

I try to "build" and "install" pysqlite? After I type "python setup.py
build" I get a lot of error messages? The first error is "src/
connection.h:33:21: error: sqlite3.h: No such file or directory". So,
I assume that the absence of the "sqlite3.h" is the origin of the
problem.

I found on the web, that this file should be either in "/usr/local/
include" or in "/usr/local/lib". I check this directories and I really
do not have the "sqlite3.h" there.

Thinks becomes even more complicated since I have no permissions to
write to the 2 above mentioned directories? So, do I have any chance
to install the pysqlite? If yes, what should I do?

Should I find the file on the web and put in in some of my directories
and then to change the path in the "setup.cfg"?

Thank you for any help.
 
S

saju.pillai

Hi,

I try to "build" and "install" pysqlite? After I type "python setup.py
build" I get a lot of error messages? The first error  is "src/
connection.h:33:21: error: sqlite3.h: No such file or directory". So,
I assume that the absence of the "sqlite3.h" is the origin of the
problem.

You can try downloading sqlite3 from the web and installing it in a
local dir. Update pysqlite setup.cfg to add these local dir names and
then try building it.

-srp
 
K

Kurda Yon

You can try downloading sqlite3 from the web and installing it in a
local dir. Update pysqlite setup.cfg to add these local dir names and
then try building it.

-srp

I see the problem. The pysqlite is a package which allows a
communication between the python and sqlite. I try to install the
"pysqlite" but I do not have the "sqlite" on my computer. So, I have
the problem. I tried to find out how to install the sqlite3 but it
seems there are no simple and clear explanations of how to do it. So,
I think I will give up and search for an easier way. Tank you for your
help.
 
D

david.lyon

Hi Kurda,

I have been through this problem. Somebody needs to write a FAQ.

Took me a few days to pinpoint the problem.

Don't know which platform but I assume Linux...

Python depends upon Sqlite... which is weird... but it is what I discovered....

When Python is being built.. it checks for sqlite3.h.. in it's
'configure' script. If it is not there it doesn't provide any support
for it.

Other databases go 'ontop' of the language... so once you install your
compiler/interpretor, you install your database. That is my experience.

Anyway, it is the other way around with sqlite. Install sqlite.. then
build python... then it will all work.....

The trick is having sqlite installed before the 'make configure' step
in the install process.

If you have sophisticated packaging system in your linux... then use that...

Regards

David
 
S

saju.pillai

        Not really (weird). Python, as of 2.5, includes the PySQLite DB-API
adapter as part of the native library/source code. BUT SQLite is NOT
part of Python (the Windows installers typically include the SQLite
engine as a convenience, but Linux installers expect the engine to
already be available).


To clarify further. sqlite is supported in python by providing python
language bindings over the sqlite *native* apis. SQLite is written in
C; pysqlite uses the SQLite C api and intelligently glues it into the
python interpreter and makes python language apis available to you.
This is why Python (pysqlite2 rather) depends on the native SQLite
libraries

This is usually how any new functionality would be made available in
python - by writing python wrappers over the existing native
libraries. The other method would be to re-implement the complete
functionality in pure python (an eg of this technique would be
paramiko which implements SSH2 in pure python)

-srp
 
S

Shawn Milochik

This is all useful and interesting stuff, but I don't think any of it
addresses the original poster's problem, which is that he has no root
access to a Linux or Unix box, and wants to get pysqlite2 working in
his home directory. I have exactly the same problem. I have tried the
"python setup.py install --home=~" method, and I get errors from GCC
that I have no permissions (and to be honest, nor the knowledge) to
overcome.

Isn't there anyway to get a Linux binary that can just be put
somewhere in the Python path so we can use sqlite? Or are those of us
without admin/root control of our boxes screwed?
 
S

saju.pillai

This is all useful and interesting stuff, but I don't think any of it
addresses the original poster's problem, which is that he has no root
access to a Linux or Unix box, and wants to get pysqlite2 working in
his home directory. I have exactly the same problem. I have tried the
"python setup.py install --home=~" method, and I get errors from GCC
that I have no permissions (and to be honest, nor the knowledge) to
overcome.

Isn't there anyway to get a Linux binary that can just be put
somewhere in the Python path so we can use sqlite? Or are those of us
without admin/root control of our boxes screwed?

1. Get sqlite3 from http://www.sqlite.org/sqlite-3.6.4.tar.gz
2. build and install sqlite3 (./configure --prefix=/any/writeable/dir
&& make install) -- you may want to supply the --disable-tcl flag if
you hit permission problems
3. get pysqlite3, edit setup.cfg libraries and include lines to point
to the lib/ and include/ dir where you installed sqlite3 in the
previous step
4. python setup.py install --home=somewhere
5. PYTHONPATH=somewhere ./python -- import pysqlite2 should work for
you
 
S

Shawn Milochik

1. Get sqlite3 from http://www.sqlite.org/sqlite-3.6.4.tar.gz
2. build and install sqlite3 (./configure --prefix=/any/writeable/dir
&& make install) -- you may want to supply the --disable-tcl flag if
you hit permission problems
3. get pysqlite3, edit setup.cfg libraries and include lines to point
to the lib/ and include/ dir where you installed sqlite3 in the
previous step
4. python setup.py install --home=somewhere
5. PYTHONPATH=somewhere ./python -- import pysqlite2 should work for
you
--


Thanks, but either I'm missing something or you're missing something.
I can't do any of what you describe on the machine I want to use
sqlite on.

I have downloaded the binary sqlite3 file from sqlite's Web site, and
I can use it with shell scripts and via the command line with no
problem. The issue is that I don't seem to have any way available to
me to use the pysqlite2 Python module.

When I try the "python setup.py --install --home=somewhere"
installation, it blows up on GCC errors that I do not have the
permissions to even attempt to fix. What I was asking above was
whether there was a way do download the pysqlite2 module as files that
I can just copy into a directory that Python thinks is part of its
path so I can use it without having to compile or build it in any way
on that machine.

Thanks,
Shawn
 
S

saju.pillai

Thanks, but either I'm missing something or you're missing something.
I can't do any of what you describe on the machine I want to use
sqlite on.

I have downloaded the binary sqlite3 file from sqlite's Web site, and

The linux binary will not work. You need the headers and the
libraries. Grab the src tar ball and build and install locally.

-srp
 
S

Shawn Milochik

Thanks, but either I'm missing something or you're missing something.
The linux binary will not work. You need the headers and the
libraries. Grab the src tar ball and build and install locally.

-srp

That is not correct. The binary *does* work, as I said last time.

For the third time, it is not possible for me to build from source on that box.

And in any case, you keep talking about sqlite3, but I'm talking about
pysqlite2.
 
T

Thorsten Kampe

* Shawn Milochik (Wed, 5 Nov 2008 12:28:46 -0500)
That is not correct. The binary *does* work, as I said last time.

For the third time, it is not possible for me to build from source on
that box.

Sure you can. There are never permission problems for compiling - only
for installing.
And in any case, you keep talking about sqlite3, but I'm talking about
pysqlite2.

You (and Kurda) keep on talking the wrong stuff. First: you don't need
pysqlite2. SQLite support is included in the latest Python as module
sqlite3.

If for whatever reason you need the latest SQLite module for Python
(2.5.0), you can simply grab an rpm or build it from source and install
it to your home directory. To build pysqlite you need the SQLite
headers. If you can't install those to default path then simply grab the
headers, put them somewhere into your home directory and tell the
pysqlite build process where to find them.

Thorsten
 
S

Shawn Milochik

* Shawn Milochik (Wed, 5 Nov 2008 12:28:46 -0500)

Sure you can. There are never permission problems for compiling - only
for installing.


You (and Kurda) keep on talking the wrong stuff. First: you don't need
pysqlite2. SQLite support is included in the latest Python as module
sqlite3.

If for whatever reason you need the latest SQLite module for Python
(2.5.0), you can simply grab an rpm or build it from source and install
it to your home directory. To build pysqlite you need the SQLite
headers. If you can't install those to default path then simply grab the
headers, put them somewhere into your home directory and tell the
pysqlite build process where to find them.

Thorsten


Okay, sorry if I haven't been specific enough. I don't know about the
original poster, but on the box I'm using, I don't have the latest
Python, the "make" command breaks because the system doesn't have the
proper libraries, and there is no sqlite3 module. I am not authorized
to fix any of that, and our support team isn't interested in helping
me because it's a Perl shop, not Python.

I'm not demanding that anyone solve my problem. I'm just asking if
there are files I can download and without compiling or building them
in any way, put them somewhere, point Python to that path, and be able
to use sqlite from Python. If the answer is no, it's no. I'm not
repeating myself because I enjoy it. For some reason everyone who has
answered me has ignored the basic question of whether this is possible
or not, so I have felt the need to reply and say so.

Thanks,
Shawn
 
K

Kurda Yon

You (and Kurda) keep on talking the wrong stuff. First: you don't need
pysqlite2. SQLite support is included in the latest Python as module
sqlite3.

By the way, I think the above statement is very helpfull. I tried to
install the "pysqlite" to be able to communicate with the "sqlite",
and then I have realized that for that I need first to install the
"sqlite"...

But I read your statement and understood that I do not need to install
neither "pysqlite" no "sqlite". In my Python session I tried to type
"from sqlite import connect" and it does not compaline. It meand that
Python see the database!!! I hope.

By the where can I find a simle tutorial about the work with the
"sqlite" from the Python?
 
S

Shawn Milochik

By the where can I find a simle tutorial about the work with the
"sqlite" from the Python?

Once you get the connection, you can pretty much just do whatever if
you know SQL. Here's some working code from one of my little projects:

#!/usr/bin/env python

from pysqlite2 import dbapi2 as sqlite

import time
#import sys

sqliteDatabase = "status.db"

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS auctions (auction_id
INTEGER PRIMARY KEY, numBids INTEGER, currentPrice INTEGER, timestamp
TEXT(50), itemTitle TEXT(100))')
connection.close()

local = time.localtime()
timeStamp = "%s-%02d-%02d_%02d:%02d" % (local[0], local[1], local[2],
local[3], local[4])

def recordExists(auctionID):

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
cursor.execute('SELECT COUNT(auction_id) FROM auctions WHERE
auction_ID = ' + auctionID.__str__())
for row in cursor:
return row[0]

cursor.close()

connection.close()

def retrieveAuctionInfo(auctionID):
connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
cursor.execute('SELECT currentPrice, numBids FROM auctions
WHERE auction_ID = ' + auctionID.__str__())
for row in cursor:
return [row[0],row[1]]

cursor.close()

def insertAuction(auctionID, currentPrice, currentBids, itemTitle):

itemTitle = itemTitle.replace('"', '""')

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
insertQuery = 'INSERT INTO auctions (auction_id, currentPrice,
numBids, timestamp, itemTitle) VALUES (%s, %s, %s, "%s", "%s")' %
(auctionID, currentPrice, currentBids, timeStamp, itemTitle)
cursor.execute(insertQuery)
connection.commit()

cursor.close()

connection.close()

def updateAuction(auctionID, currentPrice, currentBids):

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
updateQuery = 'UPDATE auctions SET currentPrice = %s, numBids =
%s, timestamp = "%s" WHERE auction_id = %s;' % (currentPrice,
currentBids, timeStamp,auctionID)
cursor.execute(updateQuery)
connection.commit()

cursor.close()
connection.close()

def getTotalAmount():

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
selectQuery = "SELECT SUM(currentPrice) FROM auctions WHERE numBids > 0;"
cursor.execute(selectQuery)
for row in cursor:
return float(row[0])

cursor.close()

connection.close()

def displayAuctions(sortBy="timestamp DESC"):

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
selectQuery = "SELECT auction_id, numBids, currentPrice,
timestamp, itemTitle FROM auctions WHERE numBids > 0 ORDER BY " +
sortBy + ";"
cursor.execute(selectQuery)
for row in cursor:
auctionID, numBids, currentPrice, timestamp, itemTitle = row

print "%25s $%6.2f (%2s bids) Last update: %16s" %
(itemTitle[:25], currentPrice, numBids, timestamp)

cursor.close()

print ""

connection.close()

if __name__ == "__main__":
displayAuctions("currentPrice DESC")
displayAuctions()
#displayAuctions("numBids DESC")
print "$%3.2f" % getTotalAmount()
 
T

Thorsten Kampe

* Kurda Yon (Wed, 5 Nov 2008 17:52:08 -0800 (PST))
By the way, I think the above statement is very helpfull. I tried to
install the "pysqlite" to be able to communicate with the "sqlite",
and then I have realized that for that I need first to install the
"sqlite"...

But I read your statement and understood that I do not need to install
neither "pysqlite" no "sqlite". In my Python session I tried to type
"from sqlite import connect" and it does not compaline. It meand that
Python see the database!!! I hope.

I don't think so. There is no "sqlite" module in Python so the above
line should give you an error. The module is called sqlite3.
By the where can I find a simle tutorial about the work with the
"sqlite" from the Python?

Guess where: in the Python documentation and on the pysqlite web site:
http://docs.python.org/library/sqlite3.html
http://oss.itsystementwicklung.de/download/pysqlite/doc/sqlite3.html

Thorsten
 
T

Thorsten Kampe

* Shawn Milochik (Wed, 5 Nov 2008 14:32:15 -0500)
Okay, sorry if I haven't been specific enough. I don't know about the
original poster, but on the box I'm using, I don't have the latest
Python, the "make" command breaks because the system doesn't have the
proper libraries, and there is no sqlite3 module. I am not authorized
to fix any of that, and our support team isn't interested in helping
me because it's a Perl shop, not Python.

I'm not demanding that anyone solve my problem. I'm just asking if
there are files I can download and without compiling or building them
in any way, put them somewhere, point Python to that path, and be able
to use sqlite from Python.

I more or less answered that already: you can grab a rpm for the same
Python version as you already have, unpack it and put the sqlite3
support files somewhere into your home directory (~/bin/python/site-
packages for example). If your Python is older than 2.5 then you have to
download the pysqlite rpms for your distribution and do the same as
above. To have Python find the modules you have to set the PYTHONPATH
environment variable. See the man page.

If your distribution doesn't provide RPMs for pysqlite then you have to
build it yourself. You have to grab the SQLite headers (they are in the
SQLite RPM probably), unpack them somewhere into your home directory and
tell the pysqlite build process where to find them. I don't exactly know
how but this is probably very easy to find out.

Thorsten
 
K

Kurda Yon

I don't think so. There is no "sqlite" module in Python so the above
line should give you an error. The module is called sqlite3.

Well, but the "above line" does not give me an error. I get an error
if I replace "sqlite" by "sqlite3". But anyway, now everything works
fine.

Thnak you everybody for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top