日食 + Jython:使用一对一对象工厂找不到 Python 模块

发布于 2024-12-12 21:23:11 字数 2130 浏览 2 评论 0原文

我正在尝试使用 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 0
ImportError: No module named building

state.path 检索了 Python 路径(其中 statePySystemState 的实例)。

到目前为止,我已经定义了相关的Java接口,实现了Python模块,并将其全部放在类路径中。此外,该项目同时添加了 Java 和 PyDev 性质,并且 Python 源文件夹位于 PYTHONPATH 上。我仍然收到上述错误。我需要在其他地方添加 Python 源文件夹(包含模块)吗?

更新:按照 Fabio 的建议(见下文),我已将 Java bin 文件添加到 Python 路径并删除了 Java 源文件。这没有解决任何问题,所以这是我的项目配置文件。

我的 PyDev 配置:

<?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>

I'm trying to get an Eclipse Java project using a Python module (in Eclipse) running, but I keep getting an error saying my Python module can't be found. I'm following the approach explained in The Definitive Guide to Python, "More Detailed One-to-One Object Factories". I think there's a problem with my project configuration/path settings, but I can't figure out what exactly.

This is the error message:

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 0
ImportError: 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>

My Java configuration:

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野侃 2024-12-19 21:23:11

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

请参阅:http://pydev.org/manual_101_project_conf2.html(最后一部分)以获取正确的参考。

For PyDev, in a Java project, you have to add the bin folder to the PYTHONPATH (i.e.: the folder with the .class files and not the one with the .java files).

See: http://pydev.org/manual_101_project_conf2.html (the last part) for a proper reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文