OCR to Add Text to File

[limo@limo ~]$ yay -Syyu jinja2
:: Synchronizing package databases...
 core                                  156.8 KiB   266 KiB/s 00:01 [------------------------------------] 100%
 extra                                1716.7 KiB   907 KiB/s 00:02 [------------------------------------] 100%
 community                               6.7 MiB  1410 KiB/s 00:05 [------------------------------------] 100%
 multilib                              170.9 KiB   247 KiB/s 00:01 [------------------------------------] 100%
 endeavouros                            33.5 KiB  28.8 KiB/s 00:01 [------------------------------------] 100%
:: Starting full system upgrade...
 there is nothing to do
:: Searching databases for updates...
:: Searching AUR for updates...
 -> Could not find all required packages:
        jinja2 (Target)
[limo@limo ~]$ 

It is not in the repos?!
Should I add a repo? how to?

UPDATE:

[limo@limo ~]$  pip install coloredlogs
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: coloredlogs in ./.local/lib/python3.10/site-packages (15.0.1)
Requirement already satisfied: humanfriendly>=9.1 in /usr/lib/python3.10/site-packages (from coloredlogs) (10.0)
[limo@limo ~]$ 

:thinking:

you should install pip, if don’t available on your system.

yay -S python-pip

and run the command

sudo pip install jinja2

that installs jinja2

For reference:
Once you’ve overcome your problems installing ocrmypdf and tesseract-data-ara (normally yay -S ocrmypdf tesseract-data-ara --needed should suffice), simply run

ocrmypdf --output-type pdf -s -l ara input.pdf output.pdf

to attach the arabic ocr data to the newly created output.pdf.
Make sure the input.pdf has a high enough resolution; else your ocr results may be underwhelming.


To check which languages tesseract can access, run
tesseract --list-langs

If you need other languages, see here; install with sudo pacman -S <package-name>

[limo@limo ~]$ pip install jinja2
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: jinja2 in ./.local/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in ./.local/lib/python3.10/site-packages (from jinja2) (2.1.1)
[limo@limo ~]$ pip install jinja2
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: jinja2 in ./.local/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in ./.local/lib/python3.10/site-packages (from jinja2) (2.1.1)
[limo@limo ~]$ 

[limo@limo ~]$  pip install coloredlogs
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: coloredlogs in ./.local/lib/python3.10/site-packages (15.0.1)
Requirement already satisfied: humanfriendly>=9.1 in /usr/lib/python3.10/site-packages (from coloredlogs) (10.0)
[limo@limo ~]$ 

Still

    from sphinx.util.rst import append_epilog, docinfo_re, prepend_prolog
  File "/home/limo/.local/lib/python3.10/site-packages/sphinx/util/rst.py", line 22, in <module>
    from jinja2 import environmentfilter
ImportError: cannot import name 'environmentfilter' from 'jinja2' (/usr/lib/python3.10/site-packages/jinja2/__init__.py)
==> ERROR: A failure occurred in build().
    Aborting...
 -> error making: python-coloredlogs
[limo@limo ~]$ 

Thank you @2000
Amazing and wonderful community as usual.
BUT I hope I can do without creating a new file!
Would giving the target file same name as source do?

I already did

yay -Syyu tesseract-data-ara

try it with sudo, you need root permissions

sudo pip install jinja2
[limo@limo ~]$ sudo pip install jinja2

[sudo] password for limo: 
Requirement already satisfied: jinja2 in /usr/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/lib/python3.10/site-packages (from jinja2) (2.1.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[limo@limo ~]$ 

Saying already satisfied!???
My system has gone bananas!?

if you look in the folder

/usr/lib/python3.10/site-packages

do you find the jinja2 folder there?

Please stop. This is horrific advice.

Never, ever use sudo pip on an Arch based system

This is a direct path to broken updates.

1 Like

i tried the commands by me, my output is different and jinja2 folder is available:

[pycrk@ovoEnd ~]$ pip install jinja2
Defaulting to user installation because normal site-packages is not writeable
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 1.6 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, jinja2
Successfully installed MarkupSafe-2.1.1 jinja2-3.1.2
[pycrk@ovoEnd ~]$ sudo pip install jinja2
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 2.3 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, jinja2
Successfully installed MarkupSafe-2.1.1 jinja2-3.1.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv                                                                                                                                                             
[pycrk@ovoEnd ~]$              

Yes,

ocrmypdf --output-type pdf -s -l ara input.pdf input.pdf

would overwrite the original pdf.

Are we sure that jinja2 being missing is even the issue?

I don’t have that installed and my build went fine.

Ooooops! I already did!
Can I revert back?

In your case, it looks like it failed to do anything. Should be OK.

1 Like

Can we see the output of pacman -Q | grep -i jinja

Yes, I have a few as follows, I tried lots of things:

jinja2
Jinja2-3.1.2-py3.10.egg-info
jinja2_time
jinja2_time-0.2.0-py3.10.egg-info

It’s probably too late for you now, but for future refererence:
It’s not recommended to use pip to install system-wide packages! Use your package manager (pacman) instead.

I’d recommend reading up on Virtual environments to create a self-contained Python environment in which you can install whatever you want with pip, without it conflicting with your system down the road.

For example:

sudo pacman -S python-virtualenv
virtualenv path/to/my_virtenv
source path/to/my_virtenv/bin/activate

would leave you in your my_virtenv environment. Now, your Python interpreter will use packages from that environment, instead of your system-wide Python install. As long as you remain in this environment you can install whatever you want with pip, it’s not going to conflict with your system.

To exit the environment, just run the command deactivate. If you want to get rid of the environment completely, just delete the folder my_virtenv.


[Edit] Dalto beat me to it.

2 Likes
[limo@limo ~]$ pacman -Q | grep -i jinja
python-jinja 1:3.1.2-2
python-jinja-time 0.2.0-7
[limo@limo ~]$ 

What does pacman -Qo /usr/lib/python3.10/site-packages/jinja2 show?

But he said

Hopefully it is still OK.

[limo@limo ~]$ yay -Syyu
:: Synchronizing package databases...
 core                                  156.8 KiB   223 KiB/s 00:01 [------------------------------------] 100%
 extra                                1716.7 KiB   723 KiB/s 00:02 [------------------------------------] 100%
 community                               6.7 MiB  1551 KiB/s 00:04 [------------------------------------] 100%
 multilib                              170.9 KiB   281 KiB/s 00:01 [------------------------------------] 100%
 endeavouros                            33.5 KiB  35.7 KiB/s 00:01 [------------------------------------] 100%
:: Starting full system upgrade...
 there is nothing to do
:: Searching databases for updates...
:: Searching AUR for updates...
 there is nothing to do
[limo@limo ~]$