Как установить pytesseract? - PullRequest
       1

Как установить pytesseract?

1 голос
/ 23 сентября 2019

У меня проблема с установкой pytesseract.Я попытался:

pip install pytesseract

Я получил ошибку:

Collecting pytesseract
  Using cached https://files.pythonhosted.org/packages/47/e5/892d78db0d26372aa376fc1b127e9cd4cc158727a76e0802069115fcbd6e/pytesseract-0.3.0.tar.gz
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from pytesseract) (5.1.0)
Installing collected packages: pytesseract
  Running setup.py install for pytesseract ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-cu7_ki6k/pytesseract/setup.py'"'"'; __file__='"'"'/tmp/pip-install-cu7_ki6k/pytesseract/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-07yttrn0/install-record.txt --single-version-externally-managed --compile
         cwd: /tmp/pip-install-cu7_ki6k/pytesseract/
    Complete output (20 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/pytesseract
    copying src/pytesseract.py -> build/lib/pytesseract
    copying src/__init__.py -> build/lib/pytesseract
    running egg_info
    writing pytesseract.egg-info/PKG-INFO
    writing dependency_links to pytesseract.egg-info/dependency_links.txt
    writing entry points to pytesseract.egg-info/entry_points.txt
    writing requirements to pytesseract.egg-info/requires.txt
    writing top-level names to pytesseract.egg-info/top_level.txt
    reading manifest file 'pytesseract.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'pytesseract.egg-info/SOURCES.txt'
    running install_lib
    creating /usr/local/lib/python3.6/dist-packages/pytesseract
    error: could not create '/usr/local/lib/python3.6/dist-packages/pytesseract': Permission denied
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-cu7_ki6k/pytesseract/setup.py'"'"'; __file__='"'"'/tmp/pip-install-cu7_ki6k/pytesseract/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-07yttrn0/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

Подушка, которую я уже установил.

pip install pillow
Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (5.1.0)

Я хотел бы запустить код для преобразованияизображение в .txt.

РЕДАКТИРОВАТЬ После вашего совета я попробовал это:

У меня есть этот .py файл, который должен преобразовывать изображения в строки.

img2str.py:

from PIL import Image
from pytesseract import image_to_string

image = Image.open('image.png', mode='r')
print(image_to_string(image))


python3 img2str.py
Traceback (most recent call last):
  File "/home/linux/.local/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 223, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract': 'tesseract'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "img2str.py", line 4, in <module>
    results = tes.image_to_string(Image.open('image.png'))
  File "/home/linux/.local/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 345, in image_to_string
    }[output_type]()
  File "/home/linux/.local/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 344, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "/home/linux/.local/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 253, in run_and_get_output
    run_tesseract(**kwargs)
  File "/home/linux/.local/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 225, in run_tesseract
    raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path



sudo pip install pytesseract --user
[sudo] heslo pro linux:    
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

По вашему совету я использовал запятую во второй раз, и она, кажется, установлена.

pip install pytesseract --user
Requirement already satisfied: pytesseract in ./.local/lib/python3.6/site-packages (0.3.0)
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from pytesseract) (5.1.0)

1 Ответ

1 голос
/ 23 сентября 2019

Эта ошибка вызвана тем, что у вас нет разрешения на создание временного файла, который требуется для установки pytesseract.

Если вы запустите pip install pytesseract --user, который должен решить вашу проблему.

Если это не решит проблему, запустите sudo pip install pytesseract --user, поскольку он использует самый высокий уровень доступа, который может предоставить системавы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...