2


I'm using Tesseract OCR and everytime I run a new session it asks for setting the TESSDATA_PREFIX variable, I do so by running the command export TESSDATA_PREFIX="PATH_TO_FILES" How can I do it inside the python script i'm running ?
Thanks !

2
  • it depends on how you run the session. Do you use subprocess? Commented Feb 2, 2014 at 11:25
  • Why, does import os; os.environ['TESSDATA_PREFIX'] = "PATH_TO_FILES" not work for you? Commented Feb 2, 2014 at 11:25

3 Answers 3

1

You can do:

 import os
 os.putenv("TESSDATA_PREFIX", "PATH_TO_FILES")

More info

http://docs.python.org/2/library/os.html#os.putenv

Sign up to request clarification or add additional context in comments.

Comments

1

Please try adding to your python:

import os
os.environ["TESSDATA_PREFIX"] = "PATH_TO_FILES"

Comments

0

You could try using os module to set environment variable:

setting:

os.environ['TESSDATA_PREFIX'] = "PATH_TO_FILES"

getting:

   pat_to_files = os.environ['TESSDATA_PREFIX']

Such variable will be accessible from the python code but it may not remain accessible for other programs when your python code quits.

If your goal is to set env variable for other program then you could try this recipe: http://code.activestate.com/recipes/159462-how-to-set-environment-variables/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.