简体   繁体   English

Windows无法在Eclipse中运行python脚本

[英]Windows can't run python script from within eclipse

I'm on a Windows machine and using Eclipse. 我在Windows计算机上,正在使用Eclipse。 My java code is invoking a python script by using : 我的Java代码通过使用调用python脚本:

Process p = Runtime.getRuntime().exec("cmd /c e:\\dev\\CodeBase\\WebService\\src\\com\\rest\\service\\PythonScript.py");

On running the code it opens the prompt for choosing a program to run the script with. 在运行代码时,它会提示您选择用于运行脚本的程序。 What can I do to make it run implicitly? 我该怎么做才能使其隐式运行?

Try running Python interpreter instead: 尝试运行Python解释器:

Process p = Runtime.getRuntime().exec("[PATH TO YOUR PYTHON DIR]\\python.exe e:\\dev\\CodeBase\\WebService\\src\\com\\rest\\service\\PythonScript.py");

Usually [PATH TO YOUR PYTHON DIR] is something like C:\\\\Python27\\\\ or C:\\\\Python34 depending on your Python version. 通常[PATH TO YOUR PYTHON DIR]类似于C:\\\\Python27\\\\C:\\\\Python34具体取决于您的Python版本。

If you have Python directory added to your system PATH variable sole .exec("python ...") will suffice. 如果您已将Python目录添加到系统PATH变量,那么sole .exec("python ...")就足够了。

You will need to convert the .py file to .exe use Py2Exe. 您将需要使用Py2Exe将.py文件转换为.exe。 You can download it and follow the instructions to convert it. 您可以下载它并按照说明进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM