관리 메뉴

솜씨좋은장씨

[Python] PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH? 해결방법 본문

Programming/Python

[Python] PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH? 해결방법

사용자 솜씨좋은장씨 2020. 12. 1. 20:52

Python에서 pdf2image 라이브러리를 활용하여 pdf를 이미지로 변경하려는 코드를 실행하려고하니

아래와 같은 오류가 발생하였습니다.

from pdf2image import convert_from_path
pages = convert_from_path("./source/" + file_list[0], 500)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/pdf2image/pdf2image.py in pdfinfo_from_path(pdf_path, userpw, poppler_path, rawdates, timeout)
    440             env["LD_LIBRARY_PATH"] = poppler_path + ":" + env.get("LD_LIBRARY_PATH", "")
--> 441         proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
    442 

~/anaconda3/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    774                                 errread, errwrite,
--> 775                                 restore_signals, start_new_session)
    776         except:

~/anaconda3/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1521                             err_msg += ': ' + repr(err_filename)
-> 1522                     raise child_exception_type(errno_num, err_msg, err_filename)
   1523                 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'pdfinfo': 'pdfinfo'

During handling of the above exception, another exception occurred:

PDFInfoNotInstalledError                  Traceback (most recent call last)
<ipython-input-5-4384f5999424> in <module>
      1 from pdf2image import convert_from_path
----> 2 pages = convert_from_path(file_list[0], 500)

~/anaconda3/lib/python3.7/site-packages/pdf2image/pdf2image.py in convert_from_path(pdf_path, dpi, output_folder, first_page, last_page, fmt, jpegopt, thread_count, userpw, use_cropbox, strict, transparent, single_file, output_file, poppler_path, grayscale, size, paths_only, use_pdftocairo, timeout)
     95         poppler_path = poppler_path.as_posix()
     96 
---> 97     page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
     98 
     99     # We start by getting the output format, the buffer processing function and if we need pdftocairo

~/anaconda3/lib/python3.7/site-packages/pdf2image/pdf2image.py in pdfinfo_from_path(pdf_path, userpw, poppler_path, rawdates, timeout)
    466     except OSError:
    467         raise PDFInfoNotInstalledError(
--> 468             "Unable to get page count. Is poppler installed and in PATH?"
    469         )
    470     except ValueError:

PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

이 글에서는 위의 오류를 해결할 방법을 적어보려합니다.

 

저는 MAC OS Big Sur 환경에서 진행하였습니다.

 

 

MAC OS X 일 경우

MAC OS 에서는 brew를 활용하여 해결할 수 있습니다.

brew 설치는 아래의 링크를 참고 바랍니다.

 

[Mac OSX] Brew 설치하기

먼저 Brew 홈페이지로 이동합니다. https://brew.sh/index_ko Homebrew The missing package manager for macOS (or Linux). brew.sh 홈페이지에서 Homebrew 설치하기 아래에 있는 명령어를 복사하여 실행하면된..

somjang.tistory.com

 

brew를 설치하였다면 poppler를 brew를 활용하여 설치합니다.

 $ brew install poppler 

 

Ubuntu 일 경우

 $ sudo apt-get install poppler-utils 

 

위의 방법을 활용한 이후에 다시 실행해보면 오류 없이 제대로 실행이 되는 것을 확인할 수 있습니다.

 

참고한 링크

 

Installation — pdf2image latest documentation

Installing poppler Poppler is the underlying project that does the magic in pdf2image. You can check if you already have it installed by calling pdftoppm -h in your terminal/cmd. Ubuntu sudo apt-get install poppler-utils Archlinux sudo pacman -S poppler Ma

pdf2image.readthedocs.io

 

읽어주셔서 감사합니다.

0 Comments
댓글쓰기 폼