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).
-
If Python is not on the System path, how will anyone ever find it? What are you asking for? A complete filesystem search for Python.exe?S.Lott– S.Lott2009-08-19 11:04:48 +00:00Commented Aug 19, 2009 at 11:04
-
The python path does not get added to the system path on windows(Needs to be done manually). I was wondering if there is a way to find out without python being there on the system path.(Other than a complete filesystem search.)Goutham– Goutham2009-08-19 11:10:48 +00:00Commented Aug 19, 2009 at 11:10
-
If it's not on the path, and there are no "assumptions" to be made, then your choices are magic and full filesystem search.S.Lott– S.Lott2009-08-19 11:21:30 +00:00Commented Aug 19, 2009 at 11:21
-
In that case my question is answered.Goutham– Goutham2009-08-19 11:30:03 +00:00Commented Aug 19, 2009 at 11:30
-
I'm still vague on this: What does "installed" means when Python is not on the PATH and cannot be run?S.Lott– S.Lott2009-08-19 11:37:45 +00:00Commented Aug 19, 2009 at 11:37
5 Answers
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.
4 Comments
python, then it isn't really "installed" is it?PATH. Then this test will fail.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.
Comments
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.
this would work
- Process process = Runtime.getRuntime().exec("cmd /c C:\Python27\python --version");