Ask coding questions

← Back to all posts
Pytesseract Auto Shell Install Package Issue
Intenzi (1)

I am using pytesseract on replit.
One of the steps to make pytesseract work is going to shell and doing this install-pkg tesseract-ocr

The issue is, if I reconnect to the repl then I have to reinstall the tesseract-ocr pkg through the shell for pytesseract to function.

Is there any way to automate this process of installing the tesseract-ocr package through shell everytime replit reconnects to my repl?

I have already tried directly installing the tesseract-ocr package through the packages list but that gives an error.

Answered by BearCoder01 (8) [earned 5 cycles]
View Answer
Comments
hotnewtop
BearCoder01 (8)

The only solution is to buy the hacker plan for "always on" repl. Your repl will never turn out, so you only install it once and then never again.

Intenzi (1)

@BearCoder01 is there any possible method where I can simply not make it a manual installation through the shell.

Like an if-else where it checks if the command is giving an error then reinstall the package.
However is it even possible to change the manual installation through shell into a code that can be run.

BearCoder01 (8)

@Intenzi you can import os. Then use it on this way.

import os

os.system("install-pkg tesseract-ocr")
Intenzi (1)

Thankyou, I can make that work in a way by putting it in if the code is going to give an error.

Intenzi (1)

@BearCoder01 One last question, as it is possible to install I assume we can also see through one of the os commands whether that package exists? If so that would make it a much simpler process to redownload if not existing instead of when there is an error.

BearCoder01 (8)

@Intenzi You can do that two!

import os

if os.path.exists("<YourFile>"):
  print("Already installed!")
else:
  os.system("install-pkg tesseract-ocr")
BearCoder01 (8)

@Intenzi Can you mark this answer as correct? :-).