Re: Switching python app from sqlite to postgres - Mailing list pgsql-novice

From Bob McConnell
Subject Re: Switching python app from sqlite to postgres
Date
Msg-id 4F8B216D.5000002@lightlink.com
Whole thread Raw
In response to Re: Switching python app from sqlite to postgres  (Monte Milanuk <memilanuk@gmail.com>)
Responses Re: Switching python app from sqlite to postgres
List pgsql-novice
Monte Milanuk wrote:
> On 04/15/2012 06:17 AM, Bob McConnell wrote:
>> sqlite is not included in either version of Python I have installed
>> (2.5.2 and 3.1.1). I tried installing it after doing the parallel
>> installation of 3.1.1, but it bound to the older version of Python. I
>> don't know anything about either Python or sqlite, so I have no idea how
>> to get them to work together.
>
> I would almost bet money that your python installs *do* have sqlite
> built-in and available.  Even distributions such as Ubuntu Linux which
> tends to break up the base install of python a bit so as to not require
> thinks like tkinter (normally also 'built-in' to python) for server
> installs, include sqlite by default.  My understanding is that it
> (sqlite) is used for a lot of small data stores when something slightly
> more than a pickle or shelve is needed.
>
> Fire up the python interpreter of your choice, and type 'import sqlite3'
> like so:
>
> monte@hp-dv4-linux:~$ python
> Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
> [GCC 4.6.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import sqlite3
>  >>> sqlite3.sqlite_version
> '3.7.7'
>  >>> quit()
> monte@hp-dv4-linux:~$ python3
> Python 3.2.2 (default, Sep  5 2011, 21:17:14)
> [GCC 4.6.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import sqlite3
>  >>> sqlite3.sqlite_version
> '3.7.7'
>  >>> quit()
> monte@hp-dv4-linux:~$
>
> Simple enough to test on your own.  You can follow along a simple
> tutorial from here if you like:
>
> http://zetcode.com/db/sqlitepythontutorial/
>
> BTW, that site has a lot of good tutorials... including one on Python +
> PostgreSQL...
>
> http://zetcode.com/db/postgresqlpythontutorial/

This is on Slackware 12.2.0, after doing an explicit install of Python 3
and then sqlite3 packages using Slackware's package management.

bash-3.1$ python
Python 2.5.2 (r252:60911, Sep 11 2008, 13:43:31)
[GCC 4.2.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sqlite3
 >>> sqlite3.sqlite_version
'3.6.6.2'
 >>> quit()
bash-3.1$ python3.1
Python 3.1.1 (r311:74480, Apr 12 2012, 09:17:32)
[GCC 4.2.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sqlite3
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/lib/python3.1/sqlite3/__init__.py", line 24, in <module>
     from sqlite3.dbapi2 import *
   File "/usr/lib/python3.1/sqlite3/dbapi2.py", line 27, in <module>
     from _sqlite3 import *
ImportError: No module named _sqlite3
 >>>

So I now have sqlite3 installed in Python 2, but not in Python 3.
Originally, it was not available in Python 2 either. So the standard
package installed it with Python 2.

Bob McConnell
N2SPP

pgsql-novice by date:

Previous
From: Monte Milanuk
Date:
Subject: Re: Switching python app from sqlite to postgres
Next
From: Monte Milanuk
Date:
Subject: Re: Switching python app from sqlite to postgres