leveldb problems with Python 3

87 views
Skip to first unread message

dd

unread,
Jun 20, 2012, 7:55:31 AM6/20/12
to py-le...@googlegroups.com

Hi Arni

I am trying to install leveldb to work with Python 3.

A couple of questions.

I followed the installation steps here:

http://code.google.com/p/py-leveldb/

First thing is that the installation process does not seem to have copied the leveldb shared library to /usr/local/lib - I had to do this manually and also do a setenv to put that directory on my path for python to find.  Is this intentional?  Anyway I did that manually and it now seems to import so that's not a major problem.

A bigger problem is the following:

Python 3.2.3 (default, May  3 2012, 15:51:42)

[GCC 4.6.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import leveldb

>>> db = leveldb.LevelDB('./db')

>>> db.Put('hello', 'world')

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>

TypeError: 'str' does not support the buffer interface

>>>

I can see in the project bugs that someone appears to have fixed this for Python 3, but it still seems to be happening to me.  Not sure why.

Are you able to throw any light on it?

Thanks for writing these drivers - it's nice to see Python 3 supported.

thanks heaps

\

arnimarj

unread,
Jun 23, 2012, 9:21:37 PM6/23/12
to py-le...@googlegroups.com
Hi,

The build scripts as they are today in the repository statically link the leveldb libraries.

Regarding the strings in Python 3, this is an issue with the unification of the string and unicode type. Strings in Python 2 were always 8-bit. The string type in Python 3 is really what unicode was in Python 3, and can be either 2 or 4 bytes per character, depending on a compilation flag.

The alternative is to use bytearray objects instead of strings. The literal syntax is b'hello', so this works:

ython 3.2.3 (default, Jun  4 2012, 15:35:24) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import leveldb; db = leveldb.LevelDB('db')
>>> db.Put(b'hello', b'world')
>>> db.Get(b'hello')
bytearray(b'world')


The example on the front page doesn't really work for Python 3.

Regards, Árni
Reply all
Reply to author
Forward
0 new messages