0

I am using language_tool_python to correct texts.

When I execute it with user "toto", everything works.

python3 offers_orthographic_correction.py

Note that Java is installed and added in ~/.bashrc and python has version 3.6

[toto@myserver ~]$ java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Problem is : when executed via crontab (owned by user toto), I have the following error :

Traceback (most recent call last):
  File "[...]/offers_orthographic_correction.py", line 338, in <module>
    grammar_tool = language_tool_python.LanguageTool('fr_FR')
  File "/usr/local/lib/python3.6/site-packages/language_tool_python/server.py", line 62, in __init__
    self._start_server_on_free_port()
  File "/usr/local/lib/python3.6/site-packages/language_tool_python/server.py", line 238, in _start_server_on_free_port
    self._start_local_server()
  File "/usr/local/lib/python3.6/site-packages/language_tool_python/server.py", line 248, in _start_local_server
    download_lt()
  File "/usr/local/lib/python3.6/site-packages/language_tool_python/download_lt.py", line 144, in download_lt
    confirm_java_compatibility()
  File "/usr/local/lib/python3.6/site-packages/language_tool_python/download_lt.py", line 75, in confirm_java_compatibility
    raise ModuleNotFoundError('No java install detected. Please install java to use language-tool-python.')
ModuleNotFoundError: No java install detected. Please install java to use language-tool-python.

Has someone an idea ?

tripleee
  • 175,061
  • 34
  • 275
  • 318
fgeorges
  • 1
  • 1
  • The symptoms you describe appear to be realated to missing environment variables, but your question doesn't include enough troubleshooting information to pinpoint which ones exactly. I'm guessing `CLASSPATH` and/or `PATH`, but examine the documentation for the tools you are struggling with. – tripleee Jun 22 '22 at 10:44
  • See also the general [tag:crontab] troubleshooting tips in https://stackoverflow.com/questions/22743548/cronjob-not-running – tripleee Jun 22 '22 at 10:48
  • @triplee I can assure you the crontab is running. I have logs and stuff. I try editing the /etc/environment as suggested in your link. – fgeorges Jun 22 '22 at 11:14
  • The troubleshooting tips may be relevant if the environment variables are not your only problem, but it's not a duplicate nomination. – tripleee Jun 22 '22 at 11:17
  • `/etc/environment` is huge overkill if you *only* need to expose the variables to `cron`; editing them into the `crontab` file is much less intrusive than setting them in everyone's environment system-wide (and the mechanisms for that are more system-dependent; `/etc/environment` may or may not be the correct location for your distro). – tripleee Jun 22 '22 at 11:19
  • Nope, I tried editing my /etc/environment as well as /etc/crontab to add the java path. I still have the same error. – fgeorges Jun 22 '22 at 11:26
  • My recommendation would be to set the variables directly in your `crontab`, but you obviously have to know which ones. Try unsetting `CLASSPATH`, `JAVA_HOME`, etc in a temporary interacive shell instance until you can repro the problem there; then you know which ones you need to add to your `crontab`. – tripleee Jun 22 '22 at 11:35
  • It worked. I added the absolute path in the crontab. My previous mistake was setting it iteratively (PATH=$PATH:$JAVA_HOME/bin) – fgeorges Jun 22 '22 at 11:44
  • Thanks a lot @tripleee. If you post an answer I can accept it. – fgeorges Jun 22 '22 at 11:45
  • Please just accept the duplicate nomination. I could normally close as duplicate but in this case I was unable to because the question was not properly tagged. It's way better to collect all good answers in one place and close other questions as duplicates than to have dozens of similar questions with valid but different answers. – tripleee Jun 22 '22 at 11:49

0 Answers0