【问题标题】:Poppler in path for pdf2imagepdf2image 路径中的 Poppler
【发布时间】:2019-04-28 02:19:17
【问题描述】:

我正在尝试使用 pdf2image,看来我需要一个名为 propeller 的东西:

(sum_env) C:\Users\antoi\Documents\Programming\projects\summarizer>python ocr.py -i fr13_idf.pdf
Traceback (most recent call last):
  File "c:\Users\antoi\Documents\Programming\projects\summarizer\sum_env\lib\site-packages\pdf2image\pdf2image.py", line 165, in __page_count
    proc = Popen(["pdfinfo", pdf_path], stdout=PIPE, stderr=PIPE)
  File "C:\Python37\lib\subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "C:\Python37\lib\subprocess.py", line 1172, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ocr.py", line 53, in <module>
    pdfspliterimager(image_path)
  File "ocr.py", line 32, in pdfspliterimager
    pages = convert_from_path("document-page%s.pdf" % i, 500)
  File "c:\Users\antoi\Documents\Programming\projects\summarizer\sum_env\lib\site-packages\pdf2image\pdf2image.py", line 30, in convert_from_path
    page_count = __page_count(pdf_path, userpw)
  File "c:\Users\antoi\Documents\Programming\projects\summarizer\sum_env\lib\site-packages\pdf2image\pdf2image.py", line 169, in __page_count
    raise Exception('Unable to get page count. Is poppler installed and in PATH?')
Exception: Unable to get page count. Is poppler installed and in PATH?

我试过this link,但下载的东西并没有解决我的问题。

【问题讨论】:

标签: python-3.x path


【解决方案1】:

pdf2image 只是poppler 的包装器(不是螺旋桨!),要使用您需要在您的机器和路径中安装 poppler-utils 的模块。

该过程在“如何安装”部分的project's README 中链接。

【讨论】:

  • 所以,在linux上,它是apt-get install poppler-utils
  • 我什至无法安装 poppler
  • 在mac上是brew install poppler
【解决方案2】:

我有同样的问题,但我已经通过更改目录在我的 django 项目中修复了它。 实际上,首先您需要将此 pdf 图像文件存储在您的媒体目录中。 然后你需要将你的当前目录更改为这个媒体目录(这个 pdf 图像文件被存储的地方)。 这是我在 django 项目中的代码 sn-p,我已将 .pdf 图像转换为 .jpg

import PIL
from PIL import Image

def convert_pdf_2_image(uploaded_image_path, uploaded_image,img_size):
    project_dir = os.getcwd()
    os.chdir(uploaded_image_path)
    file_name = str(uploaded_image).replace('.pdf','')
    output_file = file_name+'.jpg'
    pages = convert_from_path(uploaded_image, 200)
    for page in pages:
        page.save(output_file, 'JPEG')
        break
    os.chdir(project_dir)
    img = Image.open(output_file)
    img = img.resize(img_size, PIL.Image.ANTIALIAS)
    img.save(output_file)
    return output_file

【讨论】:

  • 您的代码缺少导入,如果未解决此错误的原始原因,仍会导致弹出错误消息。
【解决方案3】:

这些 pdf2image 和 pdftotext 库后端要求是 Poppler, 所以你必须安装

'conda install -c conda-forge poppler'

然后错误将得到解决。 如果仍然对您不起作用,那么您可以关注 http://blog.alivate.com.au/poppler-windows/ 安装这个库。

【讨论】:

  • 不再维护。在此处下载:github.com/oschwartz10612/poppler-windows
  • 为我工作。我用麦克。谢谢!
  • 这就是我所要做的,不需要指定poppler的路径,我使用带有conda的mac。
【解决方案4】:

首先从这里here下载Poppler,然后解压。在代码部分只需添加poppler_path=r'C:\Program Files\poppler-0.68.0\ bin'(例如)如下所示

from pdf2image import convert_from_path
images = convert_from_path("mypdf.pdf", 500,poppler_path=r'C:\Program Files\poppler-0.68.0\bin')
for i, image in enumerate(images):
    fname = 'image'+str(i)+'.png'
    image.save(fname, "PNG")

现在完成了。有了这个技巧,无需添加环境变量。如果您有任何问题,请告诉我。

【讨论】:

  • 或者,您可以将上述 poppler_path 添加到系统设置中的 windows 路径环境中。之后不要忘记重新启动。这样,您无需将其添加到每个新项目中。
【解决方案5】:

对于窗户;解决PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

【讨论】:

  • 为了安装 Choco,以 Powershell 管理员身份运行以下命令 Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
【解决方案6】:

我正在使用 Visual Studio Code 开发 Mac,但遇到了这个错误。我按照安装说明进行操作,并能够验证软件包是否已安装,但在 VSC 中运行时错误仍然存​​在。

尽管我在 settings.json 中指定了 python.condaPathpython.pythonPath,但直到激活 VSC 集成终端本身内部的 conda 环境

conda activate my_env

错误消失了..

奇怪。

【讨论】:

    【解决方案7】:

    是没有正确安装的poppler。 使用它,您可以获得正确的安装包。

    sudo apt-get install poppler-utils

    【讨论】:

      【解决方案8】:

      下载 poppler 后执行此操作.... 导入操作系统 os.environ["PATH"] = r"C:.....\poppler-xxxxxxx\bin" 使用它来制作环境,希望它有效。它对我有用。

      【讨论】:

        【解决方案9】:

        在 Windows 中

        安装适用于 Windows 的 Poppler Poppler

        • 500 = JPG 的质量

        • 路径包含 pdf 文件

        • pip 安装 pdf2img

           path = r'C:\ABC\FEF\KLH\pdf_extractor\output\break'
          
           def spliting_pdf2img( path):
               from pdf2image import convert_from_path, convert_from_bytes
               for file in os.listdir(path):
                   if file.lower().endswith(".pdf"):
                       pages = convert_from_path(os.path.join(path,file), 500,poppler_path= r'C:\ABC\DEF\Downloads\poppler-0.68.0\bin')
                       for page in pages:                    
                           page.save(os.path.join(path,file.lower().replace(".pdf",".jpg")),'JPEG')    
          

        在 Linux/UBUNTU 中 在 ubuntu/linux 终端安装以下包

        • sudo apt-get 更新

        • sudo apt-get install poppler-utils

          path = r'C:\ABC\FEF\KLH\pdf_extractor\output\break'
          
           def spliting_pdf2img( path):
               from pdf2image import convert_from_path, convert_from_bytes
               for file in os.listdir(path):
                   if file.lower().endswith(".pdf"):
                       pages = convert_from_path(os.path.join(path,file), 500)
                       for page in pages:                    
                           page.save(os.path.join(path,file.lower().replace(".pdf",".jpg")),'JPEG')
          

        【讨论】:

          【解决方案10】:

          我在我的 Mac 上遇到了同样的问题
          我通过替换来自 - poppler_path= '\usr\bin' 的 poppler_path 解决了它 "到poppler_path= '\usr\local\bin' 但是您可以尝试打印 poppler 可能在您的 mac 中的所有位置 通过echo $PATH 在终端中尝试所有选项为poppler_path=" "

          【讨论】:

          【解决方案11】:

          pdf2image 路径中的 Poppler

          在使用 pdf2image 时,需要满足一些依赖性:

          1. 安装pdf2image

            pip 安装 pdf2image

          2. 安装python-dateutil

            pip install python-dateutil

          3. Poppler 的安装

          4. 在环境变量中指定Poppler路径(系统路径)

          在 Windows 上安装 Poppler

          将 Poppler 添加到路径

          • 将安装的 Poppler 添加到位置 :C:\Users\UserName\Downloads\Release-21.11.0-0.zip
          • 将 C:\Users\UserName\Downloads\Release-21.11.0-0.zip 添加到系统 环境变量中的变量路径

          在代码中指定 poppler 路径

          pages = convert_from_path(filepath, poppler_path=r"actualpoppler_path")
          

          【讨论】:

            【解决方案12】:

            我在 Mac 上使用 Visual Studio Code 和 conda 环境时遇到了同样的问题。

            我发现我可以从命令行运行代码,但不能从 VS 代码运行。然后,我在从命令行和 VS 代码运行时打印了环境变量:

            print(os.environ)

            当我比较两者时,我注意到“PATH”变量是不同的。我的 conda 环境不在 VS 代码的“PATH”变量中。我认为这意味着 VS 代码没有正确激活我的 conda 环境。因此,我从命令行中获取了我的“PATH”并将其设置在我的 launch.json 环境变量中。然后问题就解决了。

            "configurations": [
                    {
                        "name": "Python: Current File",
                        "type": "python",
                        "request": "launch",
                        "python": "/Users/<username>/miniconda3/envs/<env_name>/bin/python",
                        "env": {
                            "PATH":"<PATH STRING from command line>"
                        },
                        "program": "${file}"
                    }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2022-12-25
              • 1970-01-01
              • 2022-07-26
              • 2020-03-09
              • 1970-01-01
              相关资源
              最近更新 更多