Re: plpython module import errors

Lists: pgsql-adminpgsql-general
From: c k <shreeseva(dot)learning(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>, pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: plpython module import errors
Date: 2011-04-28 11:19:08
Message-ID: BANLkTikG=d4n2tvVH0+aBTyHJtwC=fgFqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

Hello,
I have installed postgresql 9 on fedora 14 having python 2.7. Now
created plpythonu language in my database and created a simple
function to calculate sum of two variables.
while importing math libbrary and executing the function i got the error
PL/Python: ImportError: No module named cmath

tried to search help for this error on net and tried various things
but nothing solved this.
What can I do to solve this error.
I can still work from python interpreter directly.
Thanks in advcance.
C P Kulkarni


From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: c k <shreeseva(dot)learning(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: plpython module import errors
Date: 2011-04-28 12:49:14
Message-ID: 4DB9624A.1000104@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

On 04/28/2011 02:19 PM, c k wrote:

> Hello,
> I have installed postgresql 9 on fedora 14 having python 2.7. Now
> created plpythonu language in my database and created a simple
> function to calculate sum of two variables.
> while importing math libbrary and executing the function i got the error
> PL/Python: ImportError: No module named cmath
>
> tried to search help for this error on net and tried various things
> but nothing solved this.
> What can I do to solve this error.
> I can still work from python interpreter directly.
> Thanks in advcance.
> C P Kulkarni
This can happen if you have more then one version of python on the
server and the postgresql is using a different one then you do on the
command line. This is becuase modules are installed per version of python.
The easiest way to check this is:

create or replace function pyver() returns text as
$$
import sys
return sys.version
$$ language 'plpythonu';

select pyver()
and see if the version it returns is the same one as when you open the
interpreter.

Sim


From: Martin Gainty <mgainty(at)hotmail(dot)com>
To: <sim(at)compulab(dot)co(dot)il>, <shreeseva(dot)learning(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: plpython module import errors
Date: 2011-04-28 13:15:06
Message-ID: BLU142-W36C9DEBBD6746ECBFCA840AE9B0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general


you will have to compensate for python's version-i*i*t*c behaviour by naming the binary to the exact version of python you are calling e.g.
mv python python5 (for python version 5 binary)
mv python python6 (for python version 6 binary)

then in each of the bash scripts you are calling reference python5 or python6 the correct version
you can also setup an alias in the .bashrc to point to the 'right version'

*friends dont let friends code in python*
Martin
______________________________________________
Note de déni et de confidentialité
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> Date: Thu, 28 Apr 2011 15:49:14 +0300
> From: sim(at)compulab(dot)co(dot)il
> To: shreeseva(dot)learning(at)gmail(dot)com
> CC: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] plpython module import errors
>
> On 04/28/2011 02:19 PM, c k wrote:
>
> > Hello,
> > I have installed postgresql 9 on fedora 14 having python 2.7. Now
> > created plpythonu language in my database and created a simple
> > function to calculate sum of two variables.
> > while importing math libbrary and executing the function i got the error
> > PL/Python: ImportError: No module named cmath
> >
> > tried to search help for this error on net and tried various things
> > but nothing solved this.
> > What can I do to solve this error.
> > I can still work from python interpreter directly.
> > Thanks in advcance.
> > C P Kulkarni
> This can happen if you have more then one version of python on the
> server and the postgresql is using a different one then you do on the
> command line. This is becuase modules are installed per version of python.
> The easiest way to check this is:
>
> create or replace function pyver() returns text as
> $$
> import sys
> return sys.version
> $$ language 'plpythonu';
>
> select pyver()
> and see if the version it returns is the same one as when you open the
> interpreter.
>
> Sim
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: plpython module import errors
Date: 2011-04-28 13:30:55
Message-ID: 20110428133054.GI3783@hermes.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

On Thu, Apr 28, 2011 at 09:15:06AM -0400, Martin Gainty wrote:

> mv python python5 (for python version 5 binary)
> mv python python6 (for python version 6 binary)

Do you happen to mean 2.5 and 2.6 ?

Given that, say, our Electronic Medical Record solution
happily runs on Python 2.5, 2.6, and 2.7 I wonder what the
version problems are that you are referring to ?

Wether any Python is a wise choice for use as a
procedural language may be another matter.

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346


From: c k <shreeseva(dot)learning(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: sim(at)compulab(dot)co(dot)il, mgainty(at)hotmail(dot)com, Karsten(dot)Hilbert(at)gmx(dot)net
Subject: Re: plpython module import errors
Date: 2011-04-28 14:11:50
Message-ID: BANLkTin0hZ-Q8S7Z1ZVo-XMJSAoxhiccRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

Yes, there are three version (now). I am aware of only 2.7 installed
by default in /usr/lib directory and 3.2 which I have installed
externally. But the function given above shows version 2.6.4.
Now the question is how to change the version postresql is calling for
function execution?
I have also complied the postgresql source using python option, but
nothing happens. Is there is variable or like where we can set the
python deirectory and version postresql have to use?
Because as per manual, after installing 3.2, I have complied source,
but still it does not support to python 3.2!
Kindly give the details.
Thanks and regards,

C P Kulkarni

On 4/28/11, Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> wrote:
> On Thu, Apr 28, 2011 at 09:15:06AM -0400, Martin Gainty wrote:
>
>> mv python python5 (for python version 5 binary)
>> mv python python6 (for python version 6 binary)
>
> Do you happen to mean 2.5 and 2.6 ?
>
> Given that, say, our Electronic Medical Record solution
> happily runs on Python 2.5, 2.6, and 2.7 I wonder what the
> version problems are that you are referring to ?
>
> Wether any Python is a wise choice for use as a
> procedural language may be another matter.
>
> Karsten
> --
> GPG key ID E4071346 @ gpg-keyserver.de
> E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>


From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: c k <shreeseva(dot)learning(at)gmail(dot)com>, sim(at)compulab(dot)co(dot)il, mgainty(at)hotmail(dot)com, Karsten(dot)Hilbert(at)gmx(dot)net
Subject: Re: plpython module import errors
Date: 2011-04-28 14:29:52
Message-ID: 201104280729.53015.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

On Thursday, April 28, 2011 7:11:50 am c k wrote:
> Yes, there are three version (now). I am aware of only 2.7 installed
> by default in /usr/lib directory and 3.2 which I have installed
> externally. But the function given above shows version 2.6.4.
> Now the question is how to change the version postresql is calling for
> function execution?
> I have also complied the postgresql source using python option, but
> nothing happens. Is there is variable or like where we can set the
> python deirectory and version postresql have to use?
> Because as per manual, after installing 3.2, I have complied source,
> but still it does not support to python 3.2!

It can only compile against one and by default that will be the 'system '
version. To determine what that is , at the system command line enter:
python -V

If you want to compile against 3.2 you will have to tell Postgres that. See here
for more detail:
http://www.postgresql.org/docs/9.0/interactive/install-procedure.html

PYTHON
Full path to the Python interpreter. This will be used to determine the
dependencies for building PL/Python. Also, whether Python 2 or 3 is specified
here (or otherwise implicitly chosen) determines which variant of the PL/Python
language becomes available. See Section 42.1 for more information.

> Kindly give the details.
> Thanks and regards,
>
> C P Kulkarni
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com


From: c k <shreeseva(dot)learning(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, sim(at)compulab(dot)co(dot)il, mgainty(at)hotmail(dot)com, Karsten(dot)Hilbert(at)gmx(dot)net
Subject: Re: plpython module import errors
Date: 2011-04-28 16:27:23
Message-ID: BANLkTin=hTg_UHp4uQtSHhzSq9uoCfEHgQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

Now, I found that python version postresql is using is 2.6 and path to it is

"['/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python26.zip',
'/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/',
'/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/plat-linux2',
'/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/lib-tk',
'/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/lib-old',
'/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/lib-dynload']"

what this means? It seems that this path is of the python installation which
is used to compile default plpython.so.
If I will compile the source with python 2.7, and change the old plpython.so
with new, will my problem solved?
Thanks and regards,
CPKulkarni

On Thu, Apr 28, 2011 at 7:59 PM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>wrote:

> On Thursday, April 28, 2011 7:11:50 am c k wrote:
>
> > Yes, there are three version (now). I am aware of only 2.7 installed
>
> > by default in /usr/lib directory and 3.2 which I have installed
>
> > externally. But the function given above shows version 2.6.4.
>
> > Now the question is how to change the version postresql is calling for
>
> > function execution?
>
> > I have also complied the postgresql source using python option, but
>
> > nothing happens. Is there is variable or like where we can set the
>
> > python deirectory and version postresql have to use?
>
> > Because as per manual, after installing 3.2, I have complied source,
>
> > but still it does not support to python 3.2!
>
> It can only compile against one and by default that will be the 'system '
> version. To determine what that is , at the system command line enter:
>
> python -V
>
> If you want to compile against 3.2 you will have to tell Postgres that. See
> here for more detail:
>
> http://www.postgresql.org/docs/9.0/interactive/install-procedure.html
>
> PYTHON
>
> Full path to the Python interpreter. This will be used to determine the
> dependencies for building PL/Python. Also, whether Python 2 or 3 is
> specified here (or otherwise implicitly chosen) determines which variant of
> the PL/Python language becomes available. See Section 42.1<http://www.postgresql.org/docs/9.0/interactive/plpython-python23.html>for more information.
>
> > Kindly give the details.
>
> > Thanks and regards,
>
> >
>
> > C P Kulkarni
>
> >
>
> --
>
> Adrian Klaver
>
> adrian(dot)klaver(at)gmail(dot)com
>


From: c k <shreeseva(dot)learning(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, sim(at)compulab(dot)co(dot)il, mgainty(at)hotmail(dot)com, Karsten(dot)Hilbert(at)gmx(dot)net
Subject: Re: plpython module import errors
Date: 2011-04-28 17:14:09
Message-ID: BANLkTikZRzhLCCd6eh4PZCnxV7=O6AkFrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-general

Cheers!
Solved.
What I did is complied source with python option (it failed even giving
correct python 3.2 as per instruction given in the manual page you have
shown) for python 2.7. From build and installed postgresql, copied
plpython2.so and plpython.so to the developement server and restarted it.
and it get solved.
Thanks to all of you.
Regards,
CPKulkarni

On Thu, Apr 28, 2011 at 9:57 PM, c k <shreeseva(dot)learning(at)gmail(dot)com> wrote:

> Now, I found that python version postresql is using is 2.6 and path to it
> is
> "['/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python26.zip',
> '/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/',
> '/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/plat-linux2',
> '/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/lib-tk',
> '/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/python2.6/lib-old',
> '/home/apy/rrun/build/activepython-svn-trunk/build/py2_6_4-linux-x86-apy26-rrun/CoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIxCoReAcTiVePyThOnPrEfIx/lib/lib-dynload']"
>
> what this means? It seems that this path is of the python installation
> which is used to compile default plpython.so.
> If I will compile the source with python 2.7, and change the old
> plpython.so with new, will my problem solved?
> Thanks and regards,
> CPKulkarni
>
>
> On Thu, Apr 28, 2011 at 7:59 PM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>wrote:
>
>> On Thursday, April 28, 2011 7:11:50 am c k wrote:
>>
>> > Yes, there are three version (now). I am aware of only 2.7 installed
>>
>> > by default in /usr/lib directory and 3.2 which I have installed
>>
>> > externally. But the function given above shows version 2.6.4.
>>
>> > Now the question is how to change the version postresql is calling for
>>
>> > function execution?
>>
>> > I have also complied the postgresql source using python option, but
>>
>> > nothing happens. Is there is variable or like where we can set the
>>
>> > python deirectory and version postresql have to use?
>>
>> > Because as per manual, after installing 3.2, I have complied source,
>>
>> > but still it does not support to python 3.2!
>>
>> It can only compile against one and by default that will be the 'system '
>> version. To determine what that is , at the system command line enter:
>>
>> python -V
>>
>> If you want to compile against 3.2 you will have to tell Postgres that.
>> See here for more detail:
>>
>> http://www.postgresql.org/docs/9.0/interactive/install-procedure.html
>>
>> PYTHON
>>
>> Full path to the Python interpreter. This will be used to determine the
>> dependencies for building PL/Python. Also, whether Python 2 or 3 is
>> specified here (or otherwise implicitly chosen) determines which variant of
>> the PL/Python language becomes available. See Section 42.1<http://www.postgresql.org/docs/9.0/interactive/plpython-python23.html>for more information.
>>
>> > Kindly give the details.
>>
>> > Thanks and regards,
>>
>> >
>>
>> > C P Kulkarni
>>
>> >
>>
>> --
>>
>> Adrian Klaver
>>
>> adrian(dot)klaver(at)gmail(dot)com
>>
>
>