【问题标题】:Emacs python not able to find package/moduleEmacs python无法找到包/模块
【发布时间】:2018-04-14 08:13:34
【问题描述】:

问题

emacs python 解释器找不到我的 tesseract (tesserocr),但我可以在终端以及我的 Spyder 安装中使用 tesseract。 Emacs python 解释器能够导入 pytesseract,但找不到 tesserocr。我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eghx/agent18/project-gym/tests/thresholding.py", line 34, in image_to_string2
    print(image_to_string(img_open))
  File "/home/eghx/anaconda3/lib/python3.6/site-packages/pytesseract-0.1.7-py3.6.egg/pytesseract/pytesseract.py", line 122, in image_to_string
  File "/home/eghx/anaconda3/lib/python3.6/site-packages/pytesseract-0.1.7-py3.6.egg/pytesseract/pytesseract.py", line 46, in run_tesseract
  File "/home/eghx/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/home/eghx/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract': 'tesseract'

当我跑步时

pytesseract.image_to_string(img)

但是,当我从终端而不是桌面打开 EMACS 时,我没有收到此错误。似乎在 emacs 的桌面版本和终端版本中,path 变量的继承方式不同。奇怪!

说明

我这里有anaconda安装:/path/to/anaconda3

我已将此行添加到我的 init 文件中以运行此特定的 python 安装

(setq python-shell-interpreter "/path/to/anaconda3/bin/python")

我使用 conda install 安装了 pytesseract 和 tesserocr

which tesseract 给出:

/path/to/anaconda3/bin/tesseract

$ echo $PATH 给出:

/path/to/anaconda3/bin:/usr/local/sbin:/usr/lo....

我做了什么

我将 sys.path 从正常工作的 Spyder IDE 复制到 emacs python 解释器,但仍然无法正常工作。

我环顾四周,发现 this 但最佳答案与我的情况无关,因为我的 $PATH 变量包含必要的路径。

有人可以指导我吗?我是菜鸟。我有 emacs 27 和 ubuntu 16 和 conda 4.5.0。

【问题讨论】:

    标签: python emacs anaconda tesseract python-tesseract


    【解决方案1】:

    这可能与 OSError: [Errno 2] No such file or directory using pytesser 重复

    Answer 是根据链接中的第 3 点找到的,引用如下:

    import pytesseract
    
    pytesseract.pytesseract.tesseract_cmd = 'path-to-tesseract-including-bin'
    

    就我而言,

    import pytesseract
    pytesseract.pytesseract.tesseract_cmd = '/home/anaconda3/bin/tesseract'
    

    这只是让image_to_string 工作的临时技巧,方法是在每个文件中输入上述内容。

    目前尚不清楚为什么具有/home/anaconda3/bin 的$PATH 变量不足以使其充分工作。 This 似乎是一个稍微长期的临时解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 2017-08-21
      • 2011-10-24
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多