Thread: plpythonu and PYTHONPATH/sys.path

plpythonu and PYTHONPATH/sys.path

From
Korin Richmond
Date:
Hi,

I want to use python modules I have written in plpythonu.  I can load these
modules in functions within postgres if they are installed in the "official"
python module directories (e.g. /blah/site-packages etc.)

However, I want to use modules which are in my home file space, but I can't
get this to work.

I've tried setting PYTHONPATH to the directory containing the modules, and even
tried explicitly appending the directory to sys.path within the plpythonu
interpretter (i.e. at the beginning of the database function).  I always get an
import error, though - the module cannot be found.  Why doesn't the embedded
python interpretter use sys.path (fully?) for locating modules?

How can I use python modules in plpythonu which are located in non-standard
directories?

(I use Fedora Core 6, Postgres v. 8.1.8, Python 2.4.4)

Thanks,

Korin

--
=====================================================================
Dr. Korin Richmond              Centre for Speech Technology Research
                                    2 Buccleuch Pl, Edinburgh, EH8 9LW
                                              Tel: +44 (0)131 651 1769

http://www.cstr.ed.ac.uk/ssi/people/korin.html
=====================================================================

Re: plpythonu and PYTHONPATH/sys.path

From
Richard Huxton
Date:
Korin Richmond wrote:
> Hi,
>
> I want to use python modules I have written in plpythonu.  I can load
> these modules in functions within postgres if they are installed in the
> "official" python module directories (e.g. /blah/site-packages etc.)
>
> However, I want to use modules which are in my home file space, but I
> can't get this to work.

Does user "postgres" have access to your home directory?

--
   Richard Huxton
   Archonet Ltd

Re: plpythonu and PYTHONPATH/sys.path

From
Korin Richmond
Date:
On Tue, 6 Mar 2007, Richard Huxton wrote:

> Korin Richmond wrote:
>> Hi,
>>
>> I want to use python modules I have written in plpythonu.  I can load these
>> modules in functions within postgres if they are installed in the
>> "official" python module directories (e.g. /blah/site-packages etc.)
>>
>> However, I want to use modules which are in my home file space, but I can't
>> get this to work.
>
> Does user "postgres" have access to your home directory?

Sorry, yes, I forgot to mention I've checked it's not just a permissions problem
by putting the module in /tmp, readable by everyone, and appending "/tmp" to
sys.path in the function in the database.  Still complains that the module can't
be found though :(

(If I fire up python as user postgres, I can import the module from /tmp.)

Korin

--
=====================================================================
Dr. Korin Richmond              Centre for Speech Technology Research
                                    2 Buccleuch Pl, Edinburgh, EH8 9LW
                                              Tel: +44 (0)131 651 1769

http://www.cstr.ed.ac.uk/ssi/people/korin.html
=====================================================================

Re: plpythonu and PYTHONPATH/sys.path

From
Korin Richmond
Date:
On Tue, 6 Mar 2007, Korin Richmond wrote:

> On Tue, 6 Mar 2007, Richard Huxton wrote:
>
>> Korin Richmond wrote:
>>> Hi,
>>>
>>> I want to use python modules I have written in plpythonu.  I can load
>>> these modules in functions within postgres if they are installed in the
>>> "official" python module directories (e.g. /blah/site-packages etc.)
>>>
>>> However, I want to use modules which are in my home file space, but I
>>> can't get this to work.
>>
>> Does user "postgres" have access to your home directory?
>
> Sorry, yes, I forgot to mention I've checked it's not just a permissions
> problem by putting the module in /tmp, readable by everyone, and appending
> "/tmp" to sys.path in the function in the database.  Still complains that the
> module can't be found though :(
>
> (If I fire up python as user postgres, I can import the module from /tmp.)

Arrgh - apologies, I've just realised SELinux was the problem!

Sorry to answer my own query - but thanks for your mail Richard, which set me on
the right track again!

regards,

Korin

--
=====================================================================
Dr. Korin Richmond              Centre for Speech Technology Research
                                    2 Buccleuch Pl, Edinburgh, EH8 9LW
                                              Tel: +44 (0)131 651 1769

http://www.cstr.ed.ac.uk/ssi/people/korin.html
=====================================================================