pkg-exporter icon indicating copy to clipboard operation
pkg-exporter copied to clipboard

No module named 'apt'

Open grimsi opened this issue 3 years ago • 9 comments

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:

  1. Install python3-apt: sudp apt-get update && sudo apt-get install -y python3-apt
  2. Install the exporter: pip3 install git+https://github.com/margau/pkg-exporter
  3. Run the exporter: pkg-exporter

I confirmed this by using a fresh docker image (python:slim-bullseye) to run the importer inside of it

grimsi avatar Sep 25 '22 17:09 grimsi

Same for me

pastukhov avatar Mar 17 '23 09:03 pastukhov

Finaly get this working inside docker. See my fork https://github.com/pastukhov/pkg-exporter

pastukhov avatar Mar 19 '23 18:03 pastukhov

docker run -it -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/cache:/var/cache:ro  pkg-exporter bash

pastukhov avatar Mar 22 '23 17:03 pastukhov

Hi,

The error is still present. Are there any updates planned to correct this error?

boagg avatar Sep 21 '23 08:09 boagg

How did you install it? (venv, pipx etc.) under which os? For debian 12, i added install hints to the readme.

margau avatar Sep 21 '23 08:09 margau

Thank's for the quick reply

I tested on a debian 11 and installed via pip

boagg avatar Sep 21 '23 08:09 boagg

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?

margau avatar Sep 21 '23 08:09 margau

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.

boagg avatar Sep 21 '23 09:09 boagg

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.

margau avatar Sep 22 '23 08:09 margau