This is a problem of an old version of pypdf. The history of pypdf is a bit compliated, but the gist of it:
Use
pypdf>=3.1.0. All lowercase, no number. Since December 2022, it’s the best supported version.
Install pypdf
$ sudo -H pip install pypdf
You might need to replace pip by pip2 or pip3 if you use Python 2 or Python 3.
Use pypdf
import pypdf
WARNING: PyPDF3 and PyPDF4 are not maintained and PyPDF2 is deprecated – pypdf is the way to go!
Three potential alternatives which are maintained:
pymupdf: uses mupdfpikepdf: Uses qpdfpdfminer.six: A pure Python project. Don’t confuse it with the unmaintainedpdfminer