ERROR: ImportError: No module named 'psutil'

From: Ganesh Korde <ganeshakorde(at)gmail(dot)com>
To: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: ERROR: ImportError: No module named 'psutil'
Date: 2021-07-27 15:41:27
Message-ID: CAPNyb0UKUn_RwvD+jtmo27CqPzrOa3Ae+JuzCcWwnNXvnwPMSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

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(at)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.

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Victor Sudakov 2021-07-27 16:41:10 Re: Running PostgreSQL in Kubernetes?
Previous Message Scott Ribe 2021-07-27 12:43:09 Re: Running PostgreSQL in Kubernetes?

Browse pgsql-general by date

  From Date Subject
Next Message Marc Millas 2021-07-27 17:07:43 sort order
Previous Message Rama Krishnan 2021-07-27 15:14:33 Re: Logical replication from Rds into on-premise