No module named 'apt'
I have trouble installing the exporter, when I run it I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/pkg-exporter", line 5, in <module>
from pkg_exporter.textfile import main
File "/usr/local/lib/python3.10/site-packages/pkg_exporter/textfile.py", line 4, in <module>
from pkg_exporter.pkgmanager import apt
File "/usr/local/lib/python3.10/site-packages/pkg_exporter/pkgmanager/apt.py", line 1, in <module>
import apt
ModuleNotFoundError: No module named 'apt'
Here are the steps I used to install the exporter on Debian:
- Install python3-apt:
sudp apt-get update && sudo apt-get install -y python3-apt - Install the exporter:
pip3 install git+https://github.com/margau/pkg-exporter - Run the exporter:
pkg-exporter
I confirmed this by using a fresh docker image (python:slim-bullseye) to run the importer inside of it
Same for me
Finaly get this working inside docker. See my fork https://github.com/pastukhov/pkg-exporter
docker run -it -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/cache:/var/cache:ro pkg-exporter bash
Hi,
The error is still present. Are there any updates planned to correct this error?
How did you install it? (venv, pipx etc.) under which os? For debian 12, i added install hints to the readme.
Thank's for the quick reply
I tested on a debian 11 and installed via pip
In general, the system apt package python3-apt needs to be installed, and the python env needs access to the system libs.
Under bullseye, this worked with the system pip for me. Bookworm disabled global pip usage, i'd recommend pipx here (should also work under bullseye).
Can you paste the install and the executed commands?
To make it simpler, here is a KO dockerfile (whether with bullseye or bookworm):
FROM python:3.9.18-bullseye
RUN apt-get update && apt-get install python3-apt git -y
RUN pip install pipx
RUN cat /etc/debian_version
RUN pipx run --system-site-packages pkg-exporter
I still get the error:
ModuleNotFoundError: No module named 'apt'
Whatever OS.
I've got it working with the following dockerfile:
FROM debian:bullseye
RUN apt-get update && apt-get install python3-apt git python3-pip python3-venv -y
RUN pip3 install pipx
RUN pipx run --system-site-packages pkg-exporter
Not really sure yet why the inclusion of site packages is not working in your variant though.