pip install tesserocr 失败并出现错误“tesserocr 构建***失败”

Posted

技术标签:

【中文标题】pip install tesserocr 失败并出现错误“tesserocr 构建***失败”【英文标题】:pip install tesserocr fails with error " Failed building wheel for tesserocr" 【发布时间】:2017-09-05 02:10:05 【问题描述】:

我已经有了 leptonica 和 tesseract 的最新版本

tesseract 4.00.00alpha-365-gcf0b378
 leptonica-1.74.1
  libjpeg 8d (libjpeg-turbo 1.3.0) : libpng 1.2.50 : libtiff 4.0.3 : zlib 1.2.8

我还安装了所有依赖项,例如 python-dev

这是我在我的中执行 pip install tesserocr 时遇到的错误 虚拟环境

Collecting tesserocr
      Using cached tesserocr-2.1.3.tar.gz
    Building wheels for collected packages: tesserocr
      Running setup.py bdist_wheel for tesserocr ... error
      Complete output from command /home/ajay/virtualenvs/v2/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-L3JmI9/tesserocr/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/tmpUIPX1spip-wheel- --python-tag cp27:
      running bdist_wheel
      running build
      running build_ext
      Supporting tesseract v4.00.00dev
      Configs from pkg-config: 'libraries': ['lept', 'tesseract'], 'cython_compile_time_env': 'TESSERACT_VERSION': 262144, 'library_dirs': ['/usr/local/lib'], 'include_dirs': ['/usr/local/include']
      cythoning tesserocr.pyx to tesserocr.cpp
      building 'tesserocr' extension
      creating build
      creating build/temp.linux-x86_64-2.7
      x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -I/usr/local/include -fPIC -I/usr/local/include -I/usr/include/python2.7 -c tesserocr.cpp -o build/temp.linux-x86_64-2.7/tesserocr.o
      cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
      In file included from /usr/local/include/tesseract/genericvector.h:29:0,
                       from tesserocr.cpp:449:
      /usr/local/include/tesseract/helpers.h: In member function ‘void tesseract::TRand::set_seed(const string&)’:
      /usr/local/include/tesseract/helpers.h:50:5: error: ‘hash’ is not a member of ‘std’
           std::hash<std::string> hasher;
           ^
      /usr/local/include/tesseract/helpers.h:50:26: error: expected primary-expression before ‘>’ token
           std::hash<std::string> hasher;
                                ^
      /usr/local/include/tesseract/helpers.h:50:28: error: ‘hasher’ was not declared in this scope
           std::hash<std::string> hasher;
                                  ^
      tesserocr.cpp: In function ‘tesseract::TessResultRenderer* __pyx_f_9tesserocr_13PyTessBaseAPI__get_renderer(__pyx_obj_9tesserocr_PyTessBaseAPI*, __pyx_t_9tesseract_cchar_t*)’:
      tesserocr.cpp:16699:106: error: no matching function for call to ‘tesseract::TessPDFRenderer::TessPDFRenderer(__pyx_t_9tesseract_cchar_t*&, const char*)’
             __pyx_t_7 = new tesseract::TessPDFRenderer(__pyx_v_outputbase, __pyx_v_self->_baseapi.GetDatapath());
                                                                                                                ^
      tesserocr.cpp:16699:106: note: candidates are:
      In file included from tesserocr.cpp:459:0:
      /usr/local/include/tesseract/renderer.h:190:3: note: tesseract::TessPDFRenderer::TessPDFRenderer(const char*, const char*, bool)
         TessPDFRenderer(const char* outputbase, const char* datadir, bool textonly);
         ^
      /usr/local/include/tesseract/renderer.h:190:3: note:   candidate expects 3 arguments, 2 provided
      /usr/local/include/tesseract/renderer.h:186:16: note: tesseract::TessPDFRenderer::TessPDFRenderer(const tesseract::TessPDFRenderer&)
       class TESS_API TessPDFRenderer : public TessResultRenderer 
                      ^
      /usr/local/include/tesseract/renderer.h:186:16: note:   candidate expects 1 argument, 2 provided
      error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

      ----------------------------------------
      Failed building wheel for tesserocr
      Running setup.py clean for tesserocr
    Failed to build tesserocr
    Installing collected packages: tesserocr
      Running setup.py install for tesserocr ... error
        Complete output from command /home/ajay/virtualenvs/v2/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-L3JmI9/tesserocr/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-6eGBXb-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ajay/virtualenvs/v2/include/site/python2.7/tesserocr:
        running install
        running build
        running build_ext
        Supporting tesseract v4.00.00dev
        Configs from pkg-config: 'libraries': ['lept', 'tesseract'], 'cython_compile_time_env': 'TESSERACT_VERSION': 262144, 'library_dirs': ['/usr/local/lib'], 'include_dirs': ['/usr/local/include']
        skipping 'tesserocr.cpp' Cython extension (up-to-date)
        building 'tesserocr' extension
        creating build
        creating build/temp.linux-x86_64-2.7
        x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -I/usr/local/include -fPIC -I/usr/local/include -I/usr/include/python2.7 -c tesserocr.cpp -o build/temp.linux-x86_64-2.7/tesserocr.o
        cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
        In file included from /usr/local/include/tesseract/genericvector.h:29:0,
                         from tesserocr.cpp:449:
        /usr/local/include/tesseract/helpers.h: In member function ‘void tesseract::TRand::set_seed(const string&)’:
        /usr/local/include/tesseract/helpers.h:50:5: error: ‘hash’ is not a member of ‘std’
             std::hash<std::string> hasher;
             ^
        /usr/local/include/tesseract/helpers.h:50:26: error: expected primary-expression before ‘>’ token
             std::hash<std::string> hasher;
                                  ^
        /usr/local/include/tesseract/helpers.h:50:28: error: ‘hasher’ was not declared in this scope
             std::hash<std::string> hasher;
                                    ^
        tesserocr.cpp: In function ‘tesseract::TessResultRenderer* __pyx_f_9tesserocr_13PyTessBaseAPI__get_renderer(__pyx_obj_9tesserocr_PyTessBaseAPI*, __pyx_t_9tesseract_cchar_t*)’:
        tesserocr.cpp:16699:106: error: no matching function for call to ‘tesseract::TessPDFRenderer::TessPDFRenderer(__pyx_t_9tesseract_cchar_t*&, const char*)’
               __pyx_t_7 = new tesseract::TessPDFRenderer(__pyx_v_outputbase, __pyx_v_self->_baseapi.GetDatapath());
                                                                                                                  ^
        tesserocr.cpp:16699:106: note: candidates are:
        In file included from tesserocr.cpp:459:0:
        /usr/local/include/tesseract/renderer.h:190:3: note: tesseract::TessPDFRenderer::TessPDFRenderer(const char*, const char*, bool)
           TessPDFRenderer(const char* outputbase, const char* datadir, bool textonly);
           ^
        /usr/local/include/tesseract/renderer.h:190:3: note:   candidate expects 3 arguments, 2 provided
        /usr/local/include/tesseract/renderer.h:186:16: note: tesseract::TessPDFRenderer::TessPDFRenderer(const tesseract::TessPDFRenderer&)
         class TESS_API TessPDFRenderer : public TessResultRenderer 
                        ^
        /usr/local/include/tesseract/renderer.h:186:16: note:   candidate expects 1 argument, 2 provided
        error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

我在底部收到此错误

        ----------------------------------------
    Command "/home/ajay/virtualenvs/v2/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-L3JmI9/tesserocr/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-6eGBXb-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ajay/virtualenvs/v2/include/site/python2.7/tesserocr" failed with error code 1 in /tmp/pip-build-L3JmI9/tesserocr/

【问题讨论】:

您找到解决方案了吗? 如果您运行的是 ubuntu 14.04,请尝试从源代码构建 tesseract 3.04,它对我有用 试过了,但是没用。 【参考方案1】:

终于解决了问题

从系统中完全移除 tesseract 和 leptonica 并从源代码构建所有内容

ubuntu 14.04 的 debian 包 leptonica-dev 是问题

这些是我编译的当前版本

$ tesseract -v
tesseract 3.04.01
 leptonica-1.74.1
  libjpeg 8d (libjpeg-turbo 1.3.0) : libpng 1.2.50 : libtiff 4.0.3 : zlib 1.2.8

【讨论】:

以上是关于pip install tesserocr 失败并出现错误“tesserocr 构建***失败”的主要内容,如果未能解决你的问题,请参考以下文章

win10下pip3安装tesserocr时报错

pip install enable 失败

pip install dryscrape 失败并显示“错误:[Errno 2] 没有这样的文件或目录:'src/webkit_server'”?

pip3.6 install mysqlclient==1.3.12 失败并出现错误:未知类型名称“my_bool”;你的意思是“布尔”

Pip install matplotlib 在 M1 Mac 上失败

解决scipy安装(pip install scipy)失败,以及其他问题