由于poppler在CentOS上的Python 3.6中安装pdftotext的问题
收藏

在CentOS上安装Python3.6(Anaconda5.1.0)中的pdftotext时遇到了一些问题。
先简单介绍一下:
我在VirtualBox上使用CentOS 6.7
我知道它可以工作,因为我的it组已经在我们的服务器上安装了它。注意:我发现我们的服务器安装了C++包装,我想弄清楚它是如何得到的。
我正试图让一个现有的应用程序工作,所以我现在不想寻找一个替代pdftotext库的方法。
我按照github repo中的说明操作,并已经尝试了以下步骤:
软呢帽、红帽子和朋友:

sudo yum install gcc-c++ pkgconfig poppler-cpp-devel python-devel redhat-rpm-config

但问题似乎是围绕着波普勒cpp-devel。我在yum search poppler中看不到那个包:
============================= N/S Matched: poppler =============================
poppler-devel.i686 : Libraries and headers for poppler
poppler-devel.x86_64 : Libraries and headers for poppler
poppler-glib.i686 : Glib wrapper for poppler
poppler-glib.x86_64 : Glib wrapper for poppler
poppler-qt.i686 : Qt3 wrapper for poppler
poppler-qt.x86_64 : Qt3 wrapper for poppler
poppler-qt4.i686 : Qt4 wrapper for poppler
poppler-qt4.x86_64 : Qt4 wrapper for poppler
poppler.i686 : PDF rendering library
poppler.x86_64 : PDF rendering library
poppler-data.noarch : Encoding files
poppler-glib-devel.i686 : Development files for glib wrapper
poppler-glib-devel.x86_64 : Development files for glib wrapper
poppler-qt-devel.i686 : Development files for Qt3 wrapper
poppler-qt-devel.x86_64 : Development files for Qt3 wrapper
poppler-qt4-devel.i686 : Development files for Qt4 wrapper
poppler-qt4-devel.x86_64 : Development files for Qt4 wrapper
poppler-utils.x86_64 : Command line utilities for converting PDF files

我的IT小组给了我他们所做的尝试的指导,我试着安装poppler-develpoppler-glib。但每次尝试pip install pdftotext时,我都会得到以下输出:
[root@localhost stack]# pip install pdftotext
Collecting pdftotext
  Using cached https://files.pythonhosted.org/packages/21/35/60094dbadd9de2035873390b1cac25e01da605844eba6a07a53a82fa4adc/pdftotext-2.1.1.tar.gz
Building wheels for collected packages: pdftotext
  Building wheel for pdftotext (setup.py) ... error
  Complete output from command /root/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1mu2f1n2/pdftotext/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-khm9zova --python-tag cp36:
  /root/anaconda3/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_ext
  building 'pdftotext' extension
  creating build
  creating build/temp.linux-x86_64-3.6
  gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPOPPLER_CPP_AT_LEAST_0_30_0=0 -I/root/anaconda3/include/python3.6m -c pdftotext.cpp -o build/temp.linux-x86_64-3.6/pdftotext.o -Wall
  cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
  pdftotext.cpp:3:42: error: poppler/cpp/poppler-document.h: No such file or directory
  pdftotext.cpp:4:40: error: poppler/cpp/poppler-global.h: No such file or directory
  pdftotext.cpp:5:38: error: poppler/cpp/poppler-page.h: No such file or directory
  pdftotext.cpp:20: error: ‘poppler’ has not been declared
  pdftotext.cpp:20: error: ISO C++ forbids declaration of ‘document’ with no type
  pdftotext.cpp:20: error: expected ‘;’ before ‘*’ token
  pdftotext.cpp: In function ‘void PDF_clear(PDF*)’:
  pdftotext.cpp:26: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp:27: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp: In function ‘int PDF_create_doc(PDF*)’:
  pdftotext.cpp:66: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp:66: error: ‘poppler’ has not been declared
  pdftotext.cpp:67: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp: In function ‘int PDF_unlock(PDF*, char*)’:
  pdftotext.cpp:75: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp: In function ‘int PDF_init(PDF*, PyObject*, PyObject*)’:
  pdftotext.cpp:105: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp: In function ‘PyObject* PDF_read_page(PDF*, int)’:
  pdftotext.cpp:119: error: ‘poppler’ has not been declared
  pdftotext.cpp:119: error: expected initializer before ‘*’ token
  pdftotext.cpp:120: error: ‘poppler’ has not been declared
  pdftotext.cpp:120: error: expected ‘;’ before ‘layout_mode’
  pdftotext.cpp:123: error: ‘page’ was not declared in this scope
  pdftotext.cpp:123: error: ‘struct PDF’ has no member named ‘doc’
  pdftotext.cpp:129: error: ‘poppler’ has not been declared
  pdftotext.cpp:129: error: expected initializer before ‘rect’
  pdftotext.cpp:130: error: ‘rect’ was not declared in this scope
  pdftotext.cpp:133: error: ‘layout_mode’ was not declared in this scope
  pdftotext.cpp:133: error: ‘poppler’ has not been declared
  pdftotext.cpp:135: error: ‘poppler’ has not been declared
  pdftotext.cpp:137: error: ‘poppler’ has not been declared
  pdftotext.cpp:138: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pdftotext
  Running setup.py clean for pdftotext
Failed to build pdftotext
Installing collected packages: pdftotext
  Running setup.py install for pdftotext ... error
    Complete output from command /root/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1mu2f1n2/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 /tmp/pip-record-ghuhvuhl/install-record.txt --single-version-externally-managed --compile:
    /root/anaconda3/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_ext
    building 'pdftotext' extension
    creating build
    creating build/temp.linux-x86_64-3.6
    gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPOPPLER_CPP_AT_LEAST_0_30_0=0 -I/root/anaconda3/include/python3.6m -c pdftotext.cpp -o build/temp.linux-x86_64-3.6/pdftotext.o -Wall
    cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
    pdftotext.cpp:3:42: error: poppler/cpp/poppler-document.h: No such file or directory
    pdftotext.cpp:4:40: error: poppler/cpp/poppler-global.h: No such file or directory
    pdftotext.cpp:5:38: error: poppler/cpp/poppler-page.h: No such file or directory
    pdftotext.cpp:20: error: ‘poppler’ has not been declared
    pdftotext.cpp:20: error: ISO C++ forbids declaration of ‘document’ with no type
    pdftotext.cpp:20: error: expected ‘;’ before ‘*’ token
    pdftotext.cpp: In function ‘void PDF_clear(PDF*)’:
    pdftotext.cpp:26: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp:27: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp: In function ‘int PDF_create_doc(PDF*)’:
    pdftotext.cpp:66: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp:66: error: ‘poppler’ has not been declared
    pdftotext.cpp:67: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp: In function ‘int PDF_unlock(PDF*, char*)’:
    pdftotext.cpp:75: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp: In function ‘int PDF_init(PDF*, PyObject*, PyObject*)’:
    pdftotext.cpp:105: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp: In function ‘PyObject* PDF_read_page(PDF*, int)’:
    pdftotext.cpp:119: error: ‘poppler’ has not been declared
    pdftotext.cpp:119: error: expected initializer before ‘*’ token
    pdftotext.cpp:120: error: ‘poppler’ has not been declared
    pdftotext.cpp:120: error: expected ‘;’ before ‘layout_mode’
    pdftotext.cpp:123: error: ‘page’ was not declared in this scope
    pdftotext.cpp:123: error: ‘struct PDF’ has no member named ‘doc’
    pdftotext.cpp:129: error: ‘poppler’ has not been declared
    pdftotext.cpp:129: error: expected initializer before ‘rect’
    pdftotext.cpp:130: error: ‘rect’ was not declared in this scope
    pdftotext.cpp:133: error: ‘layout_mode’ was not declared in this scope
    pdftotext.cpp:133: error: ‘poppler’ has not been declared
    pdftotext.cpp:135: error: ‘poppler’ has not been declared
    pdftotext.cpp:137: error: ‘poppler’ has not been declared
    pdftotext.cpp:138: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/root/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1mu2f1n2/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 /tmp/pip-record-ghuhvuhl/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-1mu2f1n2/pdftotext/

我假设问题在于它正在寻找C++编译文件,而我只能得到GLIB?
我能查什么?


最佳答案:

pdftotext应该在poppler-utils中,所以请尝试yum install poppler-utils
编辑:嗯。EPEL存储库中有一个名为pypoppler的包可用于CentOS 6,它自称为“Poppler PDF呈现库的Python绑定”。我看不到它包含Poppler/cpp/{anything}的迹象,但您可以尝试一下。(您可能需要先安装pycairo。)
否则,您可以尝试安装pdftotext的earlier version(例如pip install pdftotext==1.0.0)以找到与CentOS 6兼容的。不过,最早的版本是在2017年6月发布的,所以这可能无济于事。
我想你对升级到CentOS 7不感兴趣吧?

公众号