How to determine if java is installed on a system through python?

I needed to run the jar file from python code, but before running this file I want to know if java is installed on the system or not using the python code itself. Please help thanks

+3
source share
2 answers

You can simply use system commands.

eg.

>>>import os
>>>os.system("java -version")

java version "1.5.0_19"

You will get the result, of course, assuming Java is in the classpath.

+4
source

There is no 100% reliable / portable way to do this, but the following procedure should give you some confidence that Java has been installed and configured correctly (on Linux):

  • , "JAVA_HOME" ​​ , "bin", "bin" "java".
  • , "java", "PATH", , 1.
  • "java" "-version", , Java.

, - .

, , . Java Python, , "java" . , .

+5

Source: https://habr.com/ru/post/1716071/


All Articles