3

In my Python Project, I'm trying to use refextract to parse some data from a pdf file, But I'm unable to use its extract_references_from_file feature.

I'm using sample code as mentioned on site:

from refextract import extract_references_from_file
references = extract_references_from_file('C02-1025.pdf')
print(references[0])

And getting this error;

TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

I've tried different ways to pass file path like these;

references = extract_references_from_file(r"F:\project\python\C02-1025.pdf")

references = extract_references_from_file("F:\\project\\python\\C02-1025.pdf")

but nothing worked.

I am using Python 3.7.2 and it is 64 bits.

Here is full Traceback of error:

Traceback (most recent call last):
  File "refext.py", line 16, in <module>
    references = extract_references_from_file(r"F:\project\python\C02-1025.pdf")
  File "C:\Users\Username\AppData\Local\Programs\Python\Python37\lib\site-packages\refextract\references\api.py", line 128, in extract_references_from_file
    docbody = get_plaintext_document_body(path)
  File "C:\Users\Username\AppData\Local\Programs\Python\Python37\lib\site-packages\refextract\references\engine.py", line 1412, in get_plaintext_document_body
    textbody = convert_PDF_to_plaintext(fpath, keep_layout)
  File "C:\Users\Username\AppData\Local\Programs\Python\Python37\lib\site-packages\refextract\documents\pdf.py", line 457, in convert_PDF_to_plaintext
    if not os.path.isfile(CFG_PATH_PDFTOTEXT):
  File "C:\Users\Username\AppData\Local\Programs\Python\Python37\lib\genericpath.py", line 30, in isfile
    st = os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

The refextract library relies upon the pdftotext command line utility. but when I try to install it

pip install pdftotext

It gave me this error

 ERROR: Command errored out with exit status 1:
 command: 'c:\users\usernamem\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\USER~1\\AppData\\Local\\Temp\\pip-install-l_9a5zt6\\pdftotext\\setup.py'"'"'; __file__='"'"'C:\\Users\\USER~1\\AppData\\Local\\Temp\\pip-install-l_9a5zt6\\pdftotext\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\USER~1\AppData\Local\Temp\pip-record-gpha3woc\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\username\appdata\local\programs\python\python37\Include\pdftotext'
     cwd: C:\Users\USER~1\AppData\Local\Temp\pip-install-l_9a5zt6\pdftotext\
Complete output (11 lines):
WARNING: pkg-config not found--guessing at poppler version.
         If the build fails, install pkg-config and try again.
running install
running build
running build_ext
building 'pdftotext' extension
creating build
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -DPOPPLER_CPP_AT_LEAST_0_30_0=1 "-Ic:\users\username\appdata\local\programs\python\python37\include" "-Ic:\users\username\appdata\local\programs\python\python37\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" /EHsc /Tppdftotext.cpp /Fobuild\temp.win-amd64-3.7\Release\pdftotext.obj -Wall
error: command 'cl.exe' failed: No such file or directory
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\username\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\USER~1\\AppData\\Local\\Temp\\pip-install-l_9a5zt6\\pdftotext\\setup.py'"'"'; __file__='"'"'C:\\Users\\USER~1\\AppData\\Local\\Temp\\pip-install-l_9a5zt6\\pdftotext\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\USER~1\AppData\Local\Temp\pip-record-gpha3woc\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\username\appdata\local\programs\python\python37\Include\pdftotext' Check the logs for full command output.
2
  • Can you give the full traceback of your exception? It's clearly happening somewhere in the library code, but trying to trace through the calls is tricky and the traceback should spell it out exactly.
    – Blckknght
    Jun 26, 2020 at 22:30
  • traceback added. Jun 26, 2020 at 22:34

1 Answer 1

2

The refextract library that you're using relies upon the pdftotext command line utility. It's not currently finding that program on your system, and that results in the error you describe. It's probably a bug that the error is so vague. There's some code that tries to give a better error message, but it doesn't work in this situation.

On Linux, pdftotext is usually provided by your distribution. On Windows, you usually need to install it yourself. It comes in the Xpdf tools package. You either need to install the executable somewhere in your system's PATH, or you need to point refextract to the program's location by setting the environment variable CFG_PATH_PDFTOTEXT.

2
  • Yes, pdftotext was not installed, but It gave me error on its installation. I've added complete error with traceback in question. Jun 27, 2020 at 13:54
  • You don't need the pdftotext module, just the command line utility. The link I gave in my answer has a pre-built version for Windows, which is probably easier to install. Looking at the installation instructions for the module, it seems to delegate getting the actual utilities to the anaconda distribution, which fetches the poppler package, which is based on Xpdf.
    – Blckknght
    Jun 27, 2020 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.