How to build sqlite for Python 2.4?

烂漫一生 提交于 2019-12-10 00:20:08

问题


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.


回答1:


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.




回答2:


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...?




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1455642/how-to-build-sqlite-for-python-2-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!