5

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).

7
  • 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? Commented 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.) Commented 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. Commented Aug 19, 2009 at 11:21
  • In that case my question is answered. Commented 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? Commented Aug 19, 2009 at 11:37

5 Answers 5

3

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.

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

4 Comments

The OP states that "Python does not add its path to the system Path", so how would this work?
If you can't execute python, then it isn't really "installed" is it?
@S.Lott : I installed python from net many times on my window 7 machine but when I opened the cmd prompt & typed python it never worked. Finally when I included the path in my "PATH" variable then only it started working. Probably the msi installer should do the editing of the path as well for it work automatically for any user.
IMHO, if python is installed in a customized path, and some shell rc file must be sourced to get the path into PATH. Then this test will fail.
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.

Comments

1

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.

2 Comments

Ya thats one way. But will the registry be upto date?
IIRC, Python can be installed in a "no registry updates" mode.
0

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

2 Comments

The OP states that "Python does not add its path to the system Path", so how would this work?
hey noo, it must be on PATH in windows atleast!
-2

this would work

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

1 Comment

Ya thats one way. But did the user install exactly that version of python or even use pythons default folder when installing?

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.