gpt4 book ai didi

java - Eclipse + Jython : Python module not found using one-to-one object factory

转载 作者:行者123 更新时间:2023-12-01 05:37:21 25 4
gpt4 key购买 nike

我正在尝试使用 Python 模块(在 Eclipse 中)运行 Eclipse Java 项目,但我不断收到错误消息,提示找不到我的 Python 模块。我遵循《Python 权威指南》“更详细的一对一对象工厂”中解释的方法。我认为我的项目配置/路径设置有问题,但我无法弄清楚到底是什么。

这是错误消息:

PYTHONPATH: ['.', '/opt/eclipse/plugins/org.python.pydev.jython_2.2.3.2011100616/Lib']Exception in thread "main" Traceback (innermost last):  (no code object) at line 0ImportError: No module named building

The Python path was retrieved from state.path (where state is an instance of PySystemState).

So far I've defined the relevant Java interface, implemented the Python module, and put it all on the classpath. Also, the project has both the Java and PyDev nature added, and also the Python source folder is on the PYTHONPATH. I still get the above mentioned error. Do I need to add the Python source folder (containing the module) somewhere else?

Update: as suggested by Fabio (see below), I've added the Java bin files to the Python path and removed the Java source files. That didn't solve anything, so here are my project configuration files.

My PyDev configuration:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>

<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">jython</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">jython 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/SampleJythonIntegration/pysrc</path>
<path>/SampleJythonIntegration/bin</path>
</pydev_pathproperty>
</pydev_project>

我的Java配置:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SampleJythonIntegration</name>
<comment></comment>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

最佳答案

对于 PyDev,在 Java 项目中,您必须将 bin 文件夹添加到 PYTHONPATH(即:包含 .class 文件的文件夹,而不是包含 .java 文件的文件夹)。

参见:http://pydev.org/manual_101_project_conf2.html (最后一部分)作为适当的引用。

关于java - Eclipse + Jython : Python module not found using one-to-one object factory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7946700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com