java 如何从java检查python是否安装在windows中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1299018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check if python is installed in windows from java?
提问by Goutham
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).
如果 python 安装在 Windows 中,如何从 Java 程序内部检查?Python 不会将其路径添加到系统路径中,并且不会对可能的安装路径做出任何假设(即它可以安装在任何地方)。
采纳答案by S.Lott
Use the Java Runtime to exec the following command "python --version".
使用 Java 运行时执行以下命令“python --version”。
If it works, you have Python, and the standard output is the version number.
如果它有效,你就有了 Python,标准输出是版本号。
If it doesn't work, you don't have Python.
如果它不起作用,则说明您没有 Python。
回答by Ned Batchelder
Most Python installers add keys to the Windows registry. Here's an articleabout how to add that information, you can use it to see how to read the information.
大多数 Python 安装程序将密钥添加到 Windows 注册表。这是一篇关于如何添加该信息的文章,您可以使用它来查看如何阅读信息。
回答by Espo
Have you tried querying the registry to check if it is installed? It is stored in
您是否尝试过查询注册表以检查它是否已安装?它存储在
software\python\pythoncore
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 Functionto check if python is installed.
如果用户有一个(相对)新版本的 python,安装了 MSI 包,你可以使用MsiEnumProducts 函数来检查是否安装了 python。
回答by RubyDubee
exec(String command) Executes the specified string command in a separate process. Check for Python from command
exec(String command) 在单独的进程中执行指定的字符串命令。从命令检查 Python
回答by user2964088
this would work
这行得通
- Process process = Runtime.getRuntime().exec("cmd /c C:\Python27\python --version");
- 进程 process = Runtime.getRuntime().exec("cmd /c C:\Python27\python --version");

