Python3-dev / psutil in venv

Hi guys

I have issues with sensor.systemmonitor:

Not initializing sensor.systemmonitor because could not install requirement psutil==5.4.7

14:56 (ERROR)

Unable to install package psutil==5.4.7: Failed building wheel for psutil Command “/srv/homeassistant/bin/python3 -u -c “import setuptools, tokenize;file=‘/tmp/pip-install-udg72c3u/psutil/’;f=getattr(tokenize, ‘open’, open)(file);‘\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record /tmp/pip-record-032pqrx_/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.5/psutil” failed with error code 1 in /tmp/pip-install-udg72c3u/psutil/

14:56 util/ (ERROR)

So from my understanding its missing python headers. The problem is how to install it. If I run apt-get install python3-dev I get permission denied. I could ofc run as sudo but that wont help me.

apt-get install python3-dev

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)

E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

Tried to install psutil==5.4.7 manually with same error msg as in log (ofc).
Tried to install using sudo -E

sudo -E apt-get install python3-dev
[sudo] password for homeassistant:
Reading package lists… Done
Building dependency tree
Reading state information… Done
python3-dev is already the newest version (3.6.5-3ubuntu1).

But same problem in HA log

Any ideas how to help?

Latest Ubuntu release
Install on old laptop using venv
Python 3.5.3

  1. make sure you have your venv activated.
  2. make sure your homeassistant user owns everything in your venv directory and the sub directories.
  3. try using pip3 to install it.

tried pip3
venv is activated

regarding rights for ha-user, I dont know much about venv, only followed guides from ha.
how do I check rights and access in venv?

in the venv directory

ls -l

A python virtual environment only applies to python packages installed via pip. It has no effect on system packages installed with apt. The only way to install apt packages is with sudo, and it doesn’t matter if you are within the venv or not. As apt reports it is already present, that is not the problem.

But I have just created a new venv on my Ubuntu 18.04 64 bit machine, and psutil installs without problems, so I can’t think what the problem actually is.

Please check the rights on your virtual environment with the ls -l command. If you created the virtual environment with a user other than the user you are logged in as now, it may have different rights so you may not be able to write to the directory.