pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ERROR: ImportError: No module named 'psutil'
7+ messages / 3 participants
[nested] [flat]

* ERROR: ImportError: No module named 'psutil'
@ 2021-07-27 15:41  Ganesh Korde <ganeshakorde@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Ganesh Korde @ 2021-07-27 15:41 UTC (permalink / raw)
  To: pgsql-admin

Hi Everyone,

Environment
OS : Linux ubuntu 4.4.0-87-generic
Database:  PostgreSQL 10.7 on x86_64-pc-linux-gnu,
Extension: plpython3u
Python version: Python 3.5.2

 I am trying to run a python function using the language plpython3u and I
am getting the below error, though I have installed psutil.

postgres=# select * from get_psutil_mem();
ERROR:  ImportError: No module named 'psutil'
CONTEXT:  Traceback (most recent call last):
  PL/Python function "get_psutil_mem", line 2, in <module>
    from psutil import virtual_memory, swap_memory
PL/Python function "get_psutil_mem"

 Below is the successful execution of psutil

root@ubuntu:~# python
Python 3.5.2 (default, Jan 26 2021, 13:30:48)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.cpu_times()
scputimes(user=139677.25, nice=755.4, system=53408.11, idle=10956992.84,
iowait=18110.06, irq=0.0, softirq=1294.34, steal=0.0, guest=0.0,
guest_nice=0.0)
>>>

Function details:

CREATE OR REPLACE FUNCTION get_psutil_mem(
OUT total float8, OUT used float8, OUT free float8, OUT buff_cache float8,
OUT available float8, OUT percent float8,
OUT swap_total float8, OUT swap_used float8, OUT swap_free float8, OUT
swap_percent float8
)
 LANGUAGE plpython3u
AS $FUNCTION$
from psutil import virtual_memory, swap_memory
vm = virtual_memory()
sw = swap_memory()
return vm.total, vm.used, vm.free, vm.buffers + vm.cached, vm.available,
vm.percent, sw.total, sw.used, sw.free, sw.percent
$FUNCTION$;

The above function is used by pgwatch2 to monitor memory.

*I tried installing python3.4.3 from source code but still the same
error.* Also
tried most of the solutions provided on the internet but nothing helped.
Problem is with the psutil module only.

Please let me know if I am missing anything.

Any help will be much appreciated.

Regards,
Ganesh Korde.

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

* ERROR: ImportError: No module named 'psutil'
@ 2021-08-01 14:40  Ganesh Korde <ganeshakorde@gmail.com>
  parent: Ganesh Korde <ganeshakorde@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Ganesh Korde @ 2021-08-01 14:40 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Hi Everyone,

Environment
OS : Linux ubuntu 4.4.0-87-generic
Database:  PostgreSQL 10.7 on x86_64-pc-linux-gnu,
Extension: plpython3u
Python version: Python 3.5.2

 I am trying to run a python function using the language plpython3u and I
am getting the below error, though I have installed psutil.

postgres=# select * from get_psutil_mem();
ERROR:  ImportError: No module named 'psutil'
CONTEXT:  Traceback (most recent call last):
  PL/Python function "get_psutil_mem", line 2, in <module>
    from psutil import virtual_memory, swap_memory
PL/Python function "get_psutil_mem"

 Below is the successful execution of psutil

root@ubuntu:~# python
Python 3.5.2 (default, Jan 26 2021, 13:30:48)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.cpu_times()
scputimes(user=139677.25, nice=755.4, system=53408.11, idle=10956992.84,
iowait=18110.06, irq=0.0, softirq=1294.34, steal=0.0, guest=0.0,
guest_nice=0.0)
>>>

Function details:

CREATE OR REPLACE FUNCTION get_psutil_mem(
OUT total float8, OUT used float8, OUT free float8, OUT buff_cache float8,
OUT available float8, OUT percent float8,
OUT swap_total float8, OUT swap_used float8, OUT swap_free float8, OUT
swap_percent float8
)
 LANGUAGE plpython3u
AS $FUNCTION$
from psutil import virtual_memory, swap_memory
vm = virtual_memory()
sw = swap_memory()
return vm.total, vm.used, vm.free, vm.buffers + vm.cached, vm.available,
vm.percent, sw.total, sw.used, sw.free, sw.percent
$FUNCTION$;

The above function is used by pgwatch2 to monitor memory.

*I tried installing python3.4.3 from source code but still the same
error.* Also
tried most of the solutions provided on the internet but nothing helped.
Problem is with the psutil module only.

Please let me know if I am missing anything.

Any help will be much appreciated.

Regards,
Ganesh Korde.

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

* Re: ERROR: ImportError: No module named 'psutil'
@ 2021-08-01 15:35  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Ganesh Korde <ganeshakorde@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2021-08-01 15:35 UTC (permalink / raw)
  To: Ganesh Korde <ganeshakorde@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

On 8/1/21 7:40 AM, Ganesh Korde wrote:
> Hi Everyone,
> 
> Environment
> OS : Linux ubuntu 4.4.0-87-generic
> Database:  PostgreSQL 10.7 on x86_64-pc-linux-gnu,
> Extension: plpython3u
> Python version: Python 3.5.2
> 
>   I am trying to run a python function using the language plpython3u and 
> I am getting the below error, though I have installed psutil.
> 
> postgres=# select * from get_psutil_mem();
> ERROR:  ImportError: No module named 'psutil'
> CONTEXT:  Traceback (most recent call last):
>    PL/Python function "get_psutil_mem", line 2, in <module>
>      from psutil import virtual_memory, swap_memory
> PL/Python function "get_psutil_mem"
> 

> The above function is used by pgwatch2 to monitor memory.
> 
> *I tried installing python3.4.3 from source code but still the same 
> error.* Also tried most of the solutions provided on the internet but 
> nothing helped. Problem is with the psutil module only.
> 
> Please let me know if I am missing anything.

How did you install plpython3u?

How did you install psutil?

> 
> Any help will be much appreciated.
> 
> Regards,
> Ganesh Korde.


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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

* Re: ERROR: ImportError: No module named 'psutil'
@ 2021-08-01 15:51  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2021-08-01 15:51 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Ganesh Korde <ganeshakorde@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 8/1/21 7:40 AM, Ganesh Korde wrote:
>> I am trying to run a python function using the language plpython3u and 
>> I am getting the below error, though I have installed psutil.
>> 
>> postgres=# select * from get_psutil_mem();
>> ERROR:  ImportError: No module named 'psutil'

> How did you install plpython3u?
> How did you install psutil?

Experimenting locally, I observe something that seems relevant:
I get that error message phrasing from python *2*.  In python 3,
an unknown module name draws "ModuleNotFoundError":

$ python3
Python 3.6.8 (default, Mar 18 2021, 08:58:41) 
[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from z import virtual_memory, swap_memory
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'z'

Now it's possible that the wording didn't change exactly at the 2/3
boundary, but I doubt it.  So it looks to me like the alleged plpython3u
language is actually invoking python 2.something, which is unlikely
to work well at all.

			regards, tom lane





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

* Re: ERROR: ImportError: No module named 'psutil'
@ 2021-08-01 16:30  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2021-08-01 16:30 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Ganesh Korde <ganeshakorde@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

On 8/1/21 8:51 AM, Tom Lane wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:

> 
> Now it's possible that the wording didn't change exactly at the 2/3
> boundary, but I doubt it.  So it looks to me like the alleged plpython3u
> language is actually invoking python 2.something, which is unlikely
> to work well at all.

In that vein the OP could run:

DO $$
     import sys
     plpy.notice(sys.version)
$$ LANGUAGE plpython3u;

in the database to see what plpython3u is actually pointing at?

> 
> 			regards, tom lane
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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

* Re: ERROR: ImportError: No module named 'psutil'
@ 2021-08-01 16:35  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2021-08-01 16:35 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Ganesh Korde <ganeshakorde@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

Adrian Klaver <adrian.klaver@aklaver.com> writes:
> In that vein the OP could run:

> DO $$
>      import sys
>      plpy.notice(sys.version)
> $$ LANGUAGE plpython3u;

> in the database to see what plpython3u is actually pointing at?

+1 ... looking at sys.path in the same way would also be useful.

			regards, tom lane





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

* Re: ERROR: ImportError: No module named 'psutil'
@ 2021-08-02 15:05  Ganesh Korde <ganeshakorde@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Ganesh Korde @ 2021-08-02 15:05 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general <pgsql-general@lists.postgresql.org>

Ok, thanks guys. Let me check that.

On Sun, Aug 1, 2021 at 10:05 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > In that vein the OP could run:
>
> > DO $$
> >      import sys
> >      plpy.notice(sys.version)
> > $$ LANGUAGE plpython3u;
>
> > in the database to see what plpython3u is actually pointing at?
>
> +1 ... looking at sys.path in the same way would also be useful.
>
>                         regards, tom lane
>

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


end of thread, other threads:[~2021-08-02 15:05 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 15:41 ERROR: ImportError: No module named 'psutil' Ganesh Korde <ganeshakorde@gmail.com>
2021-08-01 14:40 ` Ganesh Korde <ganeshakorde@gmail.com>
2021-08-01 15:35   ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-01 15:51     ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-01 16:30       ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-01 16:35         ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-02 15:05           ` Ganesh Korde <ganeshakorde@gmail.com>

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