-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dependency on native Tesseract OCR executable for pytesseract
The pytesseract package needs to have the `tesseract` executable available at runtime to work. By default, the Python package looks for the `tesseract` executable in the PATH. This doesn't work here, so we need to override the `tesseract_cmd` with the path to the `tesseract` executable we pulled in from Nix. I did this with a patch [based on how pytesseract is set up in Nixpkgs][1]. The patching code feels a bit fiddly. I don't know the idiomatic way to do this sort of thing. I included a test that will fail if pytesseract cannot find the `tesseract` executable. The test passed for me with both `preferWheels = true` and `preferWheels = false`, but I only included one in the test suite here, not sure if it makes sense to have both—the actual patching code had to be a bit different depending on whether the source was a wheel or not. [1]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/pytesseract/tesseract-binary.patch
- Loading branch information
1 parent
fe0dcb4
commit 9ecb280
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ poetry2nix, runCommand, python3 }: | ||
let | ||
env = poetry2nix.mkPoetryEnv { | ||
python = python3; | ||
pyproject = ./pyproject.toml; | ||
poetrylock = ./poetry.lock; | ||
preferWheels = true; | ||
}; | ||
py = env.python; | ||
in | ||
runCommand "pytesseract-test" { } '' | ||
${env}/bin/python -c 'import pytesseract; print(pytesseract.get_tesseract_version())' > $out | ||
'' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[tool.poetry] | ||
name = "pytesseract-test" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Your Name <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
pytesseract = "*" |