Emacs python 无法找到 package/module

Emacs python not able to find package/module

问题

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 的桌面版和终端版中的继承方式不同。奇数!

说明

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

我已将这一行添加到我的初始化文件中,以 运行 这个特定的 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.

This is a possible duplicate of OSError: [Errno 2] No such file or directory using pytesser

Answer 是根据 link 中的第 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 正常工作的临时 hack,方法是在每个文件中键入以上内容。

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