ModuleNotFoundError: No module named 'pdfminer.high_level'; 'pdfminer' is not a package

Probleme bei der Installation?
Antworten
Knollo
User
Beiträge: 28
Registriert: Mittwoch 10. Juni 2020, 14:44

Hallo in die Runde, ich versuche grad *.pdf mit pdfminer auszulesen.
Von der Seite https://stackoverflow.com/questions/228 ... a-pdf-file hab ich den Code:

Code: Alles auswählen

from pathlib import Path
from typing import Iterable, Any
from pdfminer.high_level import extract_pages


def show_ltitem_hierarchy(o: Any, depth=0):
    """Show location and text of LTItem and all its descendants"""
    if depth == 0:
        print('element                        x1  y1  x2  y2   text')
        print('------------------------------ --- --- --- ---- -----')

    print(
        f'{get_indented_name(o, depth):<30.30s} '
        f'{get_optional_bbox(o)} '
        f'{get_optional_text(o)}'
    )

    if isinstance(o, Iterable):
        for i in o:
            show_ltitem_hierarchy(i, depth=depth + 1)


def get_indented_name(o: Any, depth: int) -> str:
    """Indented name of LTItem"""
    return '  ' * depth + o.__class__.__name__


def get_optional_bbox(o: Any) -> str:
    """Bounding box of LTItem if available, otherwise empty string"""
    if hasattr(o, 'bbox'):
        return ''.join(f'{i:<4.0f}' for i in o.bbox)
    return ''


def get_optional_text(o: Any) -> str:
    """Text of LTItem if available, otherwise empty string"""
    if hasattr(o, 'get_text'):
        return o.get_text().strip()
    return ''




path ='C:/Users/Stefan/Downloads/XXXX.pdf'

pages = extract_pages(path)
show_ltitem_hierarchy(pages)
kopiert.
Anschließend die Pakete pdfminer und pdfminer.six erfolgreich installiert. Die Pakete liegen auch unter:

Code: Alles auswählen

C:\Users\Stefan\AppData\Local\Programs\Python\Python312\Lib\site-packages
im ersten Anlauf hat das Script auch erfolgreich seine Aufgabe getan. Also alles speichern und erstmal Pause machen.
Und nun plötzlich diese Fehlermeldung:
ModuleNotFoundError: No module named 'pdfminer.high_level'; 'pdfminer' is not a package
Im Interpreter ausgeführt:

Code: Alles auswählen

>>> import pdfminer
>>> print(pdfminer.__version__)
20221105
ist auch alles korrekt... wo kann der Fehler liegen?
Python 3.12.0 auf Win10

Code: Alles auswählen

C:\Users\Stefan\AppData\Local\Programs\Python\Python312\Lib\site-packages>pip3 install pdfminer
Collecting pdfminer
  Using cached pdfminer-20191125.tar.gz (4.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pycryptodome (from pdfminer)
  Using cached pycryptodome-3.19.0-cp35-abi3-win_amd64.whl.metadata (3.4 kB)
Using cached pycryptodome-3.19.0-cp35-abi3-win_amd64.whl (1.7 MB)
Building wheels for collected packages: pdfminer
  Building wheel for pdfminer (pyproject.toml) ... done
  Created wheel for pdfminer: filename=pdfminer-20191125-py3-none-any.whl size=6140152 sha256=8a96ba01fafd3e758fc976c112851412645c1f6430bc8163c053a30119c30121
  Stored in directory: c:\users\stefan\appdata\local\pip\cache\wheels\d1\aa\48\370f83a970d62355a2a47d2d640094a64eea932c22edae1891
Successfully built pdfminer
Installing collected packages: pycryptodome, pdfminer
Successfully installed pdfminer-20191125 pycryptodome-3.19.0

C:\Users\Stefan\AppData\Local\Programs\Python\Python312\Lib\site-packages>pip3 install pdfminer.six
Collecting pdfminer.six
  Using cached pdfminer.six-20221105-py3-none-any.whl (5.6 MB)
Requirement already satisfied: charset-normalizer>=2.0.0 in c:\users\stefan\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pdfminer.six) (2.0.10)
Requirement already satisfied: cryptography>=36.0.0 in c:\users\stefan\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pdfminer.six) (41.0.5)
Requirement already satisfied: cffi>=1.12 in c:\users\stefan\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from cryptography>=36.0.0->pdfminer.six) (1.16.0)
Requirement already satisfied: pycparser in c:\users\stefan\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from cffi>=1.12->cryptography>=36.0.0->pdfminer.six) (2.21)
Installing collected packages: pdfminer.six
Successfully installed pdfminer.six-20221105
Benutzeravatar
snafu
User
Beiträge: 6744
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

Kann es sein, dass du dein eigenes Modul auch pdfminer genannt hast?
Knollo
User
Beiträge: 28
Registriert: Mittwoch 10. Juni 2020, 14:44

hat sich erledigt, ich 'Blödm...' hab im gleichen Ordner eine Datei 'pdfminer.py' benannt. Wie muss man nur drauf sein....:-(
Danke
Antworten