ERROR: ImportError: No module named 'psutil'

From: Ganesh Korde <ganeshakorde(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: ERROR: ImportError: No module named 'psutil'
Date: 2021-08-01 14:40:07
Message-ID: CAPNyb0X=vq55ZWNuK1n+gfhPLy+J8KDn9XXcONKj30iZPYi+Kw@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.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Adrian Klaver 2021-08-01 15:35:39 Re: ERROR: ImportError: No module named 'psutil'
Previous Message Thorsten Schöning 2021-08-01 10:07:09 Any experiences with de-duplicating backup of dumps?

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2021-08-01 15:30:00 Re: postgres vacuum memory limits
Previous Message Vijaykumar Jain 2021-08-01 14:34:27 Re: postgres vacuum memory limits