pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pl/pyton: exceptions.ImportError: No module named email.Parser
4+ messages / 2 participants
[nested] [flat]

* pl/pyton: exceptions.ImportError: No module named email.Parser
@ 2005-11-27 15:17 Eugene Prokopiev <prokopiev@stc.donpac.ru>
  2005-11-27 19:34 ` Re: pl/pyton: exceptions.ImportError: No module named email.Parser Michael Fuhr <mike@fuhr.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Eugene Prokopiev @ 2005-11-27 15:17 UTC (permalink / raw)
  To: pgsql-interfaces

Hi,

I need to parse e-mail messages in pl/python functions. So, I write:

dbmail=# create or replace function get_header(varchar) returns varchar 
as $$
dbmail$# import email.Parser
dbmail$# parser = email.Parser.Parser()
dbmail$# message = parser.parse(args[0])
dbmail$# return message.get("From")
dbmail$# $$ language plpythonu;
CREATE FUNCTION
dbmail=#
dbmail=# select get_header(messageblk) from dbmail_messageblks;
ERROR:  plpython: function "get_header" failed
DETAIL:  exceptions.ImportError: No module named email.Parser

Simple pl/python functions works fine:

dbmail=# create or replace function test(varchar) returns varchar as $$
dbmail$# return args[0]
dbmail$# $$ language plpythonu;
CREATE FUNCTION
dbmail=#
dbmail=# select test('test');
  test
------
  test
(1 record)

Message parsing with standalone python works too:

$ cat mail.py
import sys
import email.Parser
parser = email.Parser.Parser()
message = parser.parse(sys.stdin)
print message.get("From")
$ python mail.py < mbox
test@mydomain.com

Why can't I use "import email.Parser" in pl/python function?

--
Thanks,
Eugene Prokopiev



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pl/pyton: exceptions.ImportError: No module named email.Parser
  2005-11-27 15:17 pl/pyton: exceptions.ImportError: No module named email.Parser Eugene Prokopiev <prokopiev@stc.donpac.ru>
@ 2005-11-27 19:34 ` Michael Fuhr <mike@fuhr.org>
  2005-11-28 05:49   ` Re: pl/pyton: exceptions.ImportError: No module named Eugene Prokopiev <prokopiev@stc.donpac.ru>
  2005-11-30 03:53   ` Re: pl/pyton: exceptions.ImportError: No module named email.Parser Michael Fuhr <mike@fuhr.org>
  0 siblings, 2 replies; 4+ messages in thread

From: Michael Fuhr @ 2005-11-27 19:34 UTC (permalink / raw)
  To: Eugene Prokopiev <prokopiev@stc.donpac.ru>; +Cc: pgsql-interfaces

On Sun, Nov 27, 2005 at 06:17:06PM +0300, Eugene Prokopiev wrote:
> dbmail=# select get_header(messageblk) from dbmail_messageblks;
> ERROR:  plpython: function "get_header" failed
> DETAIL:  exceptions.ImportError: No module named email.Parser

Your function works here with Python 2.4.2 and PostgreSQL 8.0.4 and
8.1.0, although I had to use parser.parsestr() instead of parser.parse()
because the latter expects a file-like argument (an alternative would
be to use parse() and pass a StringIO object).

As for why the import fails, might PL/Python be using a different
version of Python than the command-line python program?  What does
the following function show?

CREATE FUNCTION pyversion() RETURNS text AS $$
import sys
return sys.version + '\n' + '\n'.join(sys.path)
$$ LANGUAGE plpythonu;

Does this function show the same version and module search path as
an ordinary Python program?

python -c 'import sys; print sys.version, sys.path'

What do the following commands show?

ldd /path/to/python
ldd /path/to/plpython.so

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pl/pyton: exceptions.ImportError: No module named
  2005-11-27 15:17 pl/pyton: exceptions.ImportError: No module named email.Parser Eugene Prokopiev <prokopiev@stc.donpac.ru>
  2005-11-27 19:34 ` Re: pl/pyton: exceptions.ImportError: No module named email.Parser Michael Fuhr <mike@fuhr.org>
@ 2005-11-28 05:49   ` Eugene Prokopiev <prokopiev@stc.donpac.ru>
  1 sibling, 0 replies; 4+ messages in thread

From: Eugene Prokopiev @ 2005-11-28 05:49 UTC (permalink / raw)
  To: Michael Fuhr <mike@fuhr.org>; pgsql-interfaces

I use PostgreSQL 8.1.0 and Python 2.3.3

$ psql -U postgres test

test=# CREATE FUNCTION pyversion() RETURNS text AS $$
test$# import sys
test$# return sys.version + '\n' + '\n'.join(sys.path)
test$# $$ LANGUAGE plpythonu;
CREATE FUNCTION
test=# select pyversion();
 
                             pyversion 

------------------------------------------------------
  2.3.3 (#1, Jul  5 2004, 13:54:49)
[GCC 3.3.3 20040412 (ALT Linux, build 3.3.3-alt5)]
/usr/lib/python23.zip
/usr/lib/python2.3/
/usr/lib/python2.3/plat-linux2
/usr/lib/python2.3/lib-tk
/usr/lib/lib-dynload
(1 record)

test=# \q

$ python -c 'import sys; print sys.version, sys.path'
2.3.3 (#1, Jul  5 2004, 13:54:49)
[GCC 3.3.3 20040412 (ALT Linux, build 3.3.3-alt5)] ['', 
'/usr/lib/python23.zip', '/usr/lib/python2.3', 
'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', 
'/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages']

$ ldd /usr/bin/python
         libpython2.3.so.1.0 => /usr/lib/libpython2.3.so.1.0 (0x00116000)
         libpthread.so.0 => /lib/libpthread.so.0 (0x001fb000)
         libdl.so.2 => /lib/libdl.so.2 (0x0024f000)
         libutil.so.1 => /lib/libutil.so.1 (0x00253000)
         libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00257000)
         libm.so.6 => /lib/libm.so.6 (0x00310000)
         libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00333000)
         libc.so.6 => /lib/libc.so.6 (0x0033c000)
         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

$ ldd /usr/lib/pgsql/plpython.so
         libpython2.3.so.1.0 => /usr/lib/libpython2.3.so.1.0 (0x0011f000)
         libpthread.so.0 => /lib/libpthread.so.0 (0x00204000)
         libdl.so.2 => /lib/libdl.so.2 (0x00258000)
         libutil.so.1 => /lib/libutil.so.1 (0x0025c000)
         libm.so.6 => /lib/libm.so.6 (0x00260000)
         libc.so.6 => /lib/libc.so.6 (0x00283000)
         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

Python versions are the same

-- 
Thanks,
Eugene Prokopiev



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pl/pyton: exceptions.ImportError: No module named email.Parser
  2005-11-27 15:17 pl/pyton: exceptions.ImportError: No module named email.Parser Eugene Prokopiev <prokopiev@stc.donpac.ru>
  2005-11-27 19:34 ` Re: pl/pyton: exceptions.ImportError: No module named email.Parser Michael Fuhr <mike@fuhr.org>
@ 2005-11-30 03:53   ` Michael Fuhr <mike@fuhr.org>
  1 sibling, 0 replies; 4+ messages in thread

From: Michael Fuhr @ 2005-11-30 03:53 UTC (permalink / raw)
  To: Eugene Prokopiev <prokopiev@stc.donpac.ru>; +Cc: pgsql-interfaces

[Forwarding this message to the list so the resolution gets into
the archives.]

On Mon, Nov 28, 2005 at 09:00:56PM +0300, Eugene Prokopiev wrote:
> The problem with pl/python was in my configuration. My Linux (ALT Linux) 
> install PostgreSQL into chroot by default, so I need to copy some python 
> libs into chroot too.

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-11-30 03:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-27 15:17 pl/pyton: exceptions.ImportError: No module named email.Parser Eugene Prokopiev <prokopiev@stc.donpac.ru>
2005-11-27 19:34 ` Michael Fuhr <mike@fuhr.org>
2005-11-28 05:49   ` Re: pl/pyton: exceptions.ImportError: No module named Eugene Prokopiev <prokopiev@stc.donpac.ru>
2005-11-30 03:53   ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox