How to check if python is installed in windows fro

2019-07-04 21:47发布

问题:

How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere).

回答1:

Use the Java Runtime to exec the following command "python --version".

If it works, you have Python, and the standard output is the version number.

If it doesn't work, you don't have Python.



回答2:

Most Python installers add keys to the Windows registry. Here's an article about how to add that information, you can use it to see how to read the information.



回答3:

Have you tried querying the registry to check if it is installed? It is stored in

software\python\pythoncore

If the user has a (relatively) new version of python, that is installed with the MSI-package, you can use the MsiEnumProducts Function to check if python is installed.



回答4:

exec(String command) Executes the specified string command in a separate process. Check for Python from command



回答5:

this would work

  • Process process = Runtime.getRuntime().exec("cmd /c C:\Python27\python --version");