Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac?

Reply
Thread Tools

Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac?

 
 
Alex Quinn
Guest
Posts: n/a
 
      02-22-2010
Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm, etc.) that works out of the box on any Win/Linux/Mac machine with Python 2.6+ or 3.x? It's okay if the file format is different between machines, but I want my script to work without having to install anything.

Problems with current modules:

* Shelve used to do this. Unfortunately, since bsddb was deprecated/removed from the standard distro and Windows doesn't have dbm or gdbm, the only remaining option on Windows is dumbdbm, which is discouraged in the docs.

* Sqlite3 should fill the void now. However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers.

Potential solutions:

* Could I somehow bundle with my project the _sqlite3.so file and/or whatever else it needs? Or is there an alternate sqlite3 module I could use as a fallback that would just interface with the sqlite3 executable on the machine (i.e. /usr/local/bin/sqlite3)?

* Is there a way to drop bsddb into my project so it works out of the gate (no install) on either Linux, Windows, or Mac?

If you have any ideas, I'd be most appreciative. My objective here is just to find a portable and reliable solution that I can use for small projects.

Thanks,
Alex
--
http://alexquinn.org




 
Reply With Quote
 
 
 
 
Brad Harms
Guest
Posts: n/a
 
      02-23-2010
On Mon, 22 Feb 2010 09:10:38 -0800, Alex Quinn wrote:

> Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm,
> etc.) that works out of the box on any Win/Linux/Mac machine with Python
> 2.6+ or 3.x? It's okay if the file format is different between machines,
> but I want my script to work without having to install anything.
>
> Problems with current modules:
>
> * Shelve used to do this. Unfortunately, since bsddb was
> deprecated/removed from the standard distro and Windows doesn't have dbm
> or gdbm, the only remaining option on Windows is dumbdbm, which is
> discouraged in the docs.
>
> * Sqlite3 should fill the void now. However, in my experience, nearly
> every Linux Python install I encounter has a broken sqlite3 module
> ("ImportError: No module named _sqlite3"). It's a well-documented issue,
> but it the solution generally requires root access, which I don't have
> on these servers.
>
> Potential solutions:
>
> * Could I somehow bundle with my project the _sqlite3.so file and/or
> whatever else it needs? Or is there an alternate sqlite3 module I could
> use as a fallback that would just interface with the sqlite3 executable
> on the machine (i.e. /usr/local/bin/sqlite3)?
>
> * Is there a way to drop bsddb into my project so it works out of the
> gate (no install) on either Linux, Windows, or Mac?
>
> If you have any ideas, I'd be most appreciative. My objective here is
> just to find a portable and reliable solution that I can use for small
> projects.
>
> Thanks,
> Alex


Hi,

I'm speaking with little experience here, but one thought I had is to try
compiling Pysqlite ( http://pypi.python.org/pypi/pysqlite/2.5.6 ) for
each of your target OS's, probably using GCC cross compilers for the
platforms you aren't compiling on, then sort of "splice" them together so
that _sqlite3 always points to the binary for the current OS.

This snippet might help you get started:

import sys

# Linux binary
if 'linux' in sys.platform.lower():
import _sqlite3_linux as _sqlite3

# Windows binary
elif 'win32' == sys.platform:
import _sqlite3_windows as _sqlite3

# Mac binary
elif 'darwin' == sys.platform:
import _sqlite3_mac as _sqlite3

sys.modules['_sqlite3'] = _sqlite3


I'm not exactly sure when you would run this code. It would have to be
sometime before you import the main sqlite3 module.

--
Brad Harms -- http://alphaios.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP problem with Ruby, gem sqlite3-ruby, and SQLite3 SunSw0rd Ruby 4 07-02-2009 02:08 PM
"require 'sqlite3'" gives "no such file to load -- sqlite3 (LoadError)" Jeffrey 'jf' Lim Ruby 5 04-09-2007 10:58 AM
Need help getting CQPhone to work reliably. mike VOIP 0 01-14-2007 10:27 AM
How to make Windows see USB and card reader reliably? shoemakerted@yahoo.com Digital Photography 3 07-27-2005 12:52 AM
Can you reliably make a reference to a capture buffer? Clint Olsen Perl Misc 2 11-14-2003 04:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57