Jython:子进程模块错误,AttributeError:'module'对象没有'python'属性
我的项目是这样设置的:它从一个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'
1 个回答
0
导入一个包,比如这里的 org
,并不意味着它下面的所有子包和子模块都会自动被导入。具体哪些内容会被包含在你使用 import org
时,是由这个包自己来决定的。很明显,python
这个子包默认是不会被导入的,所以你需要单独去导入它。