0

I'm trying to read in a pdf and get the text from it. I'm new to using PyMuPDF, but I did follow code I saw online pretty much line for line. However, when I read in the document, I get a fitz.Document object that cannot be opened. Spyder returns the error, "The variable is not picklable." Has anyone ran into this problem, and do you have any ideas how to handle? I tried to switch the PDF just to be sure. I also tried using dill (dill.detect.baditems(doc)) to diagnose, but it just returns the path of my PDF.

import os
import fitz
import pickle
import dill

file_i = r'C:\Users\FilesToRead\EEI (4968).pdf'
doc = fitz.open(filename = file_i, filetype="pdf")

I've omitted the rest of the code. The error starts with the doc variable.

  • You've either omitted the code that was causing the error (please include a full stack trace in the question), or the error is caused specifically by the .pdf you're trying to read. Just a simple `import fitz` and `fitz.open(filename='file.pdf', filetype="pdf")` does not cause the error and your code only consist of imports that don't do anything otherwise. – Grismar Jun 01 '22 at 01:00
  • So the other code was setting the working environment, which I removed because I changed the code to reference the full file location to be certain. To make sure it wasn't the pdf, I have tried three different PDFs. I'm uninstalling and reinstalling PyMuPDF to see if there is something corrupted in the install? – Richard Strott Jun 01 '22 at 16:16
  • To update on this: I uninstalled and reinstalled PyMuPDF and still have the same problem. – Richard Strott Jun 01 '22 at 17:44
  • If you follow these steps: create a new virtual environment, install pymupdf, create a Python file with only the code above, and run it. Do you have the same issue? What version of Python are you using? Have you tried with other pdf documents? I was unable to reproduce the issue with various versions of Python 3 on Windows. Given the type of error you mentioned, the problem is more likely with Spyder than your code or the library - if you search online, you can find many instances of users seeing this error when looking at certain object types using Spyder. Try another editor perhaps? – Grismar Jun 01 '22 at 23:10
  • Does it work if you use open() first? – Clement Genninasca Jul 27 '22 at 06:56

0 Answers0