Import tesseract error

我是研究僧i 提交于 2019-12-24 07:31:30

问题


I'm trying to import tesseract in Python with a Mac Maverick, but I'm getting the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tesseract.py", line 26, in <module>
    _tesseract = swig_import_helper()
  File "tesseract.py", line 18, in swig_import_helper
    import _tesseract
ImportError: No module named _tesseract

I followed these steps to install tesseract: https://code.google.com/p/python-tesseract/wiki/HowToCompilePythonTesseractForMacMountainLion

What should i do to fix this?

UPDATE:

Traceback of python setup.py build

os=darwin
Current Version : tesseract
~~~cv_pc~~~
{'extra_link_args': ['not', 'found', 'sh:', 'command', 'pkg-config:']}
['extra_link_args']
Traceback (most recent call last):
  File "setup.py", line 160, in <module>
    libname="open"+item.split("libopen")[1].split(".")[0]
IndexError: list index out of range

UPDATE 2 homwbrew version:

Message for python setup.py install --user

os=darwin Current Version : tesseract ~~~cv_pc~~~ {'extra_link_args': ['No', 'Perhaps', 'variable', 'in', 'containing', 'to', 'not', 'should', 'environment', 'opencv', 'add', 'you', "`opencv.pc'", 'Package', 'PKG_CONFIG_PATH', 'search', 'package', 'was', "'opencv'", 'directory', 'found', 'the', 'path.', 'pkg-config']} ['extra_link_args'] Traceback (most recent call last): File "setup.py", line 160, in libname="open"+item.split("libopen")[1].split(".")[0]

IndexError: list index out of range

UPDATE 3 : from steps 1-3 all works great. But at step 4, i get stuck at python setup.py clean

which prints this message:

os=darwin
Current Version : tesseract
~~~cv_pc~~~
{'extra_link_args': ['/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_features2d.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_objdetect.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_video.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_imgproc.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_ocl.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_contrib.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_superres.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_nonfree.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_flann.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_legacy.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_core.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_gpu.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_ts.a', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_videostab.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_highgui.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_ml.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_stitching.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_calib3d.dylib', '/usr/local/Cellar/opencv/2.4.7.1/lib/libopencv_photo.dylib'], 'include_dirs': ['/usr/local/Cellar/opencv/2.4.7.1/include/opencv', '/usr/local/Cellar/opencv/2.4.7.1/include']}
['extra_link_args', 'include_dirs']
add lib: opencv_features2d
add lib: opencv_objdetect
add lib: opencv_video
add lib: opencv_imgproc
add lib: opencv_ocl
add lib: opencv_contrib
add lib: opencv_superres
add lib: opencv_nonfree
add lib: opencv_flann
add lib: opencv_legacy
add lib: opencv_core
add lib: opencv_gpu
add lib: opencv_ts
add lib: opencv_videostab
add lib: opencv_highgui
add lib: opencv_ml
add lib: opencv_stitching
add lib: opencv_calib3d
add lib: opencv_photo
===========['stdc++', 'tesseract', 'lept', 'opencv_features2d', 'opencv_objdetect', 'opencv_video', 'opencv_imgproc', 'opencv_ocl', 'opencv_contrib', 'opencv_superres', 'opencv_nonfree', 'opencv_flann', 'opencv_legacy', 'opencv_core', 'opencv_gpu', 'opencv_ts', 'opencv_videostab', 'opencv_highgui', 'opencv_ml', 'opencv_stitching', 'opencv_calib3d', 'opencv_photo']===========
['.', '/usr/local/include/opencv2', '/usr/local/include/opencv']
Traceback (most recent call last):
  File "setup.py", line 251, in <module>
    swig_opts=["-c++", "-I"+inclpath('tesseract'),
TypeError: cannot concatenate 'str' and 'NoneType' objects

回答1:


The reason you can't import it successfully is that you never installed it successfully.

Your output from setup.py shows this: it's failing with an exception.

So, why were you able to import tesseract and get far enough for code in tesseract.py to fail, instead of not even being able to find it? My guess is that you started Python with your current working directory in the middle of the tesseract source tree, so the source-code copy of tesseract.py was found, even though nothing is installed. But it's also certainly possible that you have an incomplete, broken install, especially since you tried untarring a binary copy for the wrong version of OS X before trying to install via setup.py.

Anyway, what you want to know is how to fix it, not why it isn't working, right?

Well, right at the very top of the instructions you linked, it says:

obsolete now !! use homebrew version pls Compile for HomeBrew

The fact that the instructions you're following weren't updated for Mavericks, and link to a binary package made specifically for 10.8 only (and possibly for older MacPorts code as well) is a good sign that they really mean it when they say "obsolete", two exclamation points and everything.

Before you follow the Homebrew instructions, unless you have some other need for MacPorts, I would suggest uninstalling MacPorts completely. You can usually do this with just sudo rm -rf /opt/local, then editing your ~/.bash_profile to remove all references to /opt/local, but you may want to check for the latest instructions on the MacPorts site first. If you're afraid of doing this, you can always just sudo mv /opt/local /opt/local-bak, which will leave it there, but out of the way.

Also, do not use your existing checkout of the source code. It's got a broken, incomplete build in it, and who knows how that will affect any attempt to build it again. Just remove that directory entirely, and when you get to the svn checkout step of the instructions, you'll get a brand new, clean copy.

And then, just start at the top of the How to compile python-tesseract for Homebrew(Mac Mountain Lion/Maverick) page.

When you get to step 4, don't do both steps, just do one or the other. I'd suggest the first version, building from source, because it will probably be more obvious, and easier to recover from, if anything goes wrong. But if you do the second version, installing the binary, make sure to get the 10.9 version this time, not the 10.8.




回答2:


I ran into this problem. The only issue was that I had to run:

sudo ldconfig

Running tesseract -v from the command line confirms whether this is an issue.



来源:https://stackoverflow.com/questions/21054818/import-tesseract-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!