运行PDF拆分脚本时遇TypeError: __init__() got unexpected keyword argument 'strict'
Hey there, let's get this sorted out for you. That error you're hitting almost always boils down to a version mismatch between the PDF processing library your script is using (I'd bet it's PyPDF2, since this is super common with that tool) and the code you've written.
What's causing this?
The strict keyword argument was used in older versions of PyPDF2 to control how the library handles malformed PDFs. But starting with PyPDF2 v2.0+, this parameter was removed entirely. So if:
- You're running an older script that uses
strictwith a newer PyPDF2 version, or - You've installed a newer library but your code is written for an older release, you'll hit this exact error.
Step-by-step fixes:
First, confirm your library and version
Check your script's import statements—look for lines likeimport PyPDF2orfrom PyPDF2 import PdfReader. Then run this command in your terminal to check the installed version:pip show PyPDF2Adjust based on your version
- If you have PyPDF2 v2.0 or newer:
Go to line 115 of your script (where the error is triggering) and remove thestrictkeyword argument entirely. For example, if your code looks like this:
Change it to:reader = PyPDF2.PdfReader("your_file.pdf", strict=False)reader = PyPDF2.PdfReader("your_file.pdf") - If you have an older PyPDF2 version (pre-2.0) but need the
strictparameter:
Upgrade to the latest stable version to avoid other compatibility issues:
Then remove thepip install --upgrade PyPDF2strictargument as above, since it's no longer supported.
- If you have PyPDF2 v2.0 or newer:
If it's not PyPDF2
If you're using a different PDF library (like pdfplumber or another tool), the same logic applies: check the library's latest docs to see if thestrictparameter was deprecated or renamed, then adjust your code accordingly.
Quick check
Double-check line 115 of your 3. Split Invoice & SuppDocs.py file—this is where you're initializing the PDF reader, and that's where the strict argument is hiding that's causing the conflict.
内容的提问来源于stack exchange,提问作者Harry Adkins

