无法获取环境,+ java.lang.ExceptionInInitializerError,追踪 IO 错误:文件未找到 -
我在一台64位的电脑上运行Windows 7。
我使用的是NetBeans 6.9.1(已经安装了Python插件)。
我还安装了:Python 2.7.1(64位),JDK 6更新24(64位)。
我对术语提取感兴趣,所以下载了MontyLingua,它可以在Java和/或Python中运行。
这是链接:http://web.media.mit.edu/~hugo/montylingua/
当我尝试运行压缩包中的Sample.java代码时,遇到了这些问题:
****** MontyLingua v.2.1 ******
***** by hugo@media.mit.edu *****
Failed to get environment, environ will be empty: (0, 'Failed to execute command ([\'sh\', \'-c\', \'env\']):
java.io.IOException: Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified')
java.lang.ExceptionInInitializerError
Caused by: Traceback (innermost last):
File "C:\work\montylingua-2.0\copy\JMontyLingua.py", line 0, in __init__
File "C:\work\montylingua-2.0\copy\MontyLingua.py", line 0, in __init__
File "C:\work\montylingua-2.0\copy\MontyLemmatiser.py", line 0, in __init__
IOError: File not found -
at org.python.core.Py.IOError(Py.java)
at org.python.core.PyFile._setup(PyFile.java)
at org.python.core.PyFile.<init>(PyFile.java)
at org.python.core.__builtin__.open(__builtin__.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyObject.__call__(PyObject.java)
at montylingua.MontyLemmatiser$_PyInner.__init__$5(MontyLemmatiser.java:5312)
at montylingua.MontyLemmatiser$_PyInner.call_function(MontyLemmatiser.java:5219)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyFunction.__call__(PyFunction.java)
at org.python.core.PyInstance.__init__(PyInstance.java)
at org.python.core.PyClass.__call__(PyClass.java)
at org.python.core.PyObject.__call__(PyObject.java)
at montylingua.MontyLingua$_PyInner.__init__$1(MontyLingua.java:218)
at montylingua.MontyLingua$_PyInner.call_function(MontyLingua.java:163)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyFunction.__call__(PyFunction.java)
at org.python.core.PyInstance.__init__(PyInstance.java)
at org.python.core.PyClass.__call__(PyClass.java)
at org.python.core.PyObject.__call__(PyObject.java)
at montylingua.JMontyLingua$_PyInner.__init__$1(JMontyLingua.java:85)
at montylingua.JMontyLingua$_PyInner.call_function(JMontyLingua.java:63)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyFunction.__call__(PyFunction.java)
at org.python.core.PyInstance.__init__(PyInstance.java)
at org.python.core.Py.initProxy(Py.java)
at montylingua.JMontyLingua.__initProxy__(JMontyLingua.java:256)
at montylingua.JMontyLingua.<init>(JMontyLingua.java:234)
at montylinguaapplication.MontySample.<clinit>(MontySample.java:8)
Could not find the main class: montylinguaapplication.MontySample. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
我对Java有一些了解,因为我有一点编程经验。但我对Python一无所知。
我已经设置了“ MONTYLINGUA”这个环境变量,这是程序运行所必需的。
我看到有人提到Jython,遇到和我一样的第一个错误,但我没能从他们提出的解决方案中找到办法。(其他帖子链接:Jython - javaos.getenv()给出“无法获取环境,environ将为空”)
如果有人能正确运行这个.java文件,能否推荐一些解决办法。
我也可以上传Java代码,但我觉得这已经过时,因为在上面提到的网站上很容易找到。
在项目中,我还包括了JyDT_Update_Site_1.4.15的压缩包,以防这能有所帮助,但不幸的是没有任何变化。
也许我需要在某个特定的文件中添加一些代码,就像其他帖子提到的那样,但我不知道该在我的系统中添加什么和在哪里添加。
谢谢你的时间。
4 个回答
看起来这段Python代码是在尝试运行一个命令行指令。
但是,因为你是在Windows系统上,这样做是行不通的。
这让我想知道,这真的是在Python中获取环境的标准方法吗?
解决办法是要在 Jython 的 注册文件 中设置一个属性 python.os
。
你可以按照这些步骤找到注册文件:http://www.jython.org/archive/21/docs/registry.html#finding。
看起来这个问题和你链接的帖子里的问题是一样的。
‘执行命令失败 ([\'sh\', \'-c\', \'env\']): java.io.IOException: 无法运行程序 "sh":
这意味着 jython 被设置成认为它是在某种 UNIX 系统上运行。