views:

592

answers:

4

I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:

error: command 'gcc' failed with exit status 1

As far as I understood the problems appears because version of my Python is 2.4.3 and SQLite is integrated in Python since 2.5. However, I also found out that it IS possible to build sqlite for Python 2.4 (using some tricks, probably).

Does anybody know how to build sqlite for Python 2.4?

As another option I could try to install higher version of Python. However I do not have root privileges. Does anybody know what will be the easiest way to solve the problem (build SQLite fro Python 2.4, or install newer version of Python)? I have to mention that I would not like to overwrite the old version version of Python.

Thank you in advance.

A: 

If you don't have root privileges, I would recommend installing a more recent version of Python in your home directory and then adding your local version to your PATH. It seems easier to go that direction than to try to make sqlite work with an old version of Python.

You will also be doing yourself a favor by using a recent version of Python, because you'll have access to the numerous recent improvements in the language.

Christian Oudard
+1  A: 

You can download and install Python to your home directory.

$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install

Then, (if you are using bash) in your .bash_profile do

export PATH=$HOME/opt/bin/:$PATH
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH

Then, source the file to make it available

$ cd
$ source .bash_profile
$ python -V

where python -V will return the python version. If the correct version appears, any packages that you run with Python's setup.py util (assuming the developer followed the correct conventions) will install in ~/opt/lib/python2.x/site-packages directory.

Andrew Sledge
A: 

Download pysqlite here, cd into the directory you downloaded to, unpack the tarball:

$ tar xzf pysqlite-2.5.5.tar.gz

then just do (if your permissions are set right for this; may need sudo otherwise):

$ cd pysqlite-2.5.5
$ python2.4 setup.py install

one error does appear in the copious output:

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/pysqlite2/test/py25tests.py", line 48
    with self.con:
            ^
SyntaxError: invalid syntax

since as clearly shown that file is for py 2.5 tests only (with statement not present in 2.4!-). Nevertheless the install is successful:

$ python2.4 -c'import pysqlite2'
$

All this is on Mac OS X 10.5 but using python2.4 separately installed from the system-supplied Python 2.5.

The error you report doesn't tell us much -- maybe you're missing the headers or libraries for sqlite itself? Can you show us other output lines around that single error msg...?

Alex Martelli
A: 

I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.

Adam Feldman