【问题标题】:Jython: Error in subprocess module, AttributeError: 'module' object has no attribute 'python'Jython:子进程模块中的错误,AttributeError:“模块”对象没有属性“python”
【发布时间】:2011-05-22 17:31:17
【问题描述】:

我的项目是这样设置的,它从一个 Java 类开始,该类使用 PythonInterpreter.initialize 方法将我的 python 路径设置为 jython Lib 目录和一个包含“org/curious/neofelis/我的 jython 文件”。然后我创建一个 PythonInterpreter 并让它执行我的主 jython 文件。

我猜这是非正统的,但它一直在工作,但是当我尝试使用 Popen 时出现此错误

File "/home/steven/jython/Lib/subprocess.py", line 1163, in _get_handles
  elif isinstance(stdout, org.python.core.io.RawIOBase):

在尝试重现此错误时,我发现我可以做到这一点

from org.python.util import PythonInterpreter

#A PythonInterpreter running inside a PythonInterpreter!
interpreter = PythonInterpreter()
interpreter.exec("print 3+6");
sys.exit(0)

但这没有飞

import org

interpreter = org.python.util.PythonInterpreter()
interpreter.exec("print 3+6");
sys.exit(0)

  File "/home/steven/neofelis/src/main/jython/org/curious/neofelis/main.py", line 34, in <module>
    interpreter = org.python.util.PythonInterpreter()
AttributeError: 'module' object has no attribute 'python'

【问题讨论】:

    标签: java python subprocess jython


    【解决方案1】:

    导入一个包——在这种情况下是org——不会总是导入它的所有子包和子模块。当您执行import org 时,将由包来定义将包含的内容。显然python子包默认是不包含在导入中的,所以需要显式导入。

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 2017-01-31
      • 1970-01-01
      • 2015-03-09
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      相关资源
      最近更新 更多