简体   繁体   中英

Python - Slate3k Giving me an type error after pdfminer install

I'm on Python 3.8.3 on windows 10.

I am working on a pdfparser and I initially found slate3k to use with Python 3.X . I got a basic script working and started to test it on some PDFs. I had some issues with some text not being parsed properly so I started to look into PDFMiner .

After reading through the documentation for PDFMiner , I decided to install that a give it a go as there was some functionality from it that would be super useful for my use case.

However, I figured out soon after that PDFMiner doesn't work with Python 3.x . I uninstalled it and went back to using slate3k .

When I did this, I started to get a bunch of errors. I then uninstalled slate3k and re-installed hoping to fix it. Still got the errors. I re-installed PDFMiner and get rid of those errors but now I stuck with the below error and I'm at a loss for what to do next.

Exception has occurred: TypeError __init__() missing 1 required positional argument: 'parser'

Here is the code (please note I haven't done much error trapping and it's still a work in progress, I'm more at the "proof of concept" stage):

import re, os
import slate3k as slate

# variable define
CurWkDir = os.getcwd()
tags= list()
rev= str()
FileName = str()
ProperFileName = str()
parsed = str()

# open file and create if it doesn't exist
xref = open('parsed from pdf xref.csv', 'w+')
xref.write('File Name, Rev, Tag')

for files in os.listdir(CurWkDir):

    # find pdf files
    if files.endswith('.pdf'):

        tags.clear()
        rev = ""
        FileName = ""
        ProperFileName = ""

        #extract revision, file name, create proper file name
        rev = re.findall(r'[0-9]{,2}[A-Z]{1}[0-9]{,2}',files)[0]
        FileName = re.findall(r'[A-Z]+[0-9]+-[A-Z]+-[0-9]+-[0-9]+|[A-Z]+[0-9]+-[A-Z]+-[A-Z]+[0-9]+-[0-9]+|[A-Z]+[0-9]+-[A-Z]+-[A-Z]+[0-9]+[A-Z]+-[0-9]+', files)[0]
        ProperFileName = FileName + "(" + rev[0: len(rev) - 1] + ")"

        # Parse through PDF to find tags
        fileopen = open(files, 'rb')
        print("Reading", files)
        raw = slate.PDF(fileopen)
        print("Finished reading", files)
        parsed = raw[0]
        parsedstripped = parsed.replace("\n"," ")
        rawtags = re.findall(r'[0-9]+[A-Z]+-[0-9]+|[0-9]+[A-Z]+[0-9]{1,5}|[0-9]{3}[A-Z]+[0-9]+', parsed, re.I)
        fileopen.close
        print(parsedstripped)

        for t in rawtags:

            if t not in tags:

                row = ProperFileName + "," + rev + "," + t + "\n"
                xref.write(row)
                tags.append(t)

xref.close()

The error comes at Line 34 raw = slate.PDF(fileopen)

Any insight into what I did to break the functionality of slate3k is appreciated.

Thanks,

JT

I looked into the dependencies on slate3k by looking at pip show slate3k and I found a couple of programs it was dependent on.

I uninstalled slate3k , pdfminer3k and pdfminer and then re-installed slate3k .

Now everything seems to be working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM