【发布时间】:2020-04-01 09:38:46
【问题描述】:
我想使用Runtime.getRuntime().exec 执行一个简单的python 脚本Runtime.getRuntime().exec("python test.py"),它只包含很少的导入,但是它失败并出现错误1。我跟踪了错误,发现一些库没有找到:
Traceback (most recent call last):
File "/Users/firetiti/NetBeans/FiReTiTiLiB/Test.py", line 6, in <module>
from PIL import Image
ImportError: No module named PIL
当我在终端中执行相同的脚本时,一切都很好。于是我把python换成了pythonRuntime.getRuntime().exec("/somewhere/in/my/computer/python3.6 test.py")的绝对路径,果然奏效了。
所以看来Runtime.getRuntime().exec没有使用配置好的python版本。我该如何解决?
【问题讨论】:
标签: java runtime.exec