从Jython在Python中运行Python模块 [英] Running Python modules in Python, from Jython

查看:210
本文介绍了从Jython在Python中运行Python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经陷入一个复杂的环境中,在那里我正在使用Python库,但是我们拥有的其他一切都在Java中.我们希望能够从Java访问和使用Python库,因此我们开始研究和使用Jython.

I have been dropped into a complicated environment, where I am working with a Python library but everything else we have is in Java. We want to be able to access and use the Python library from Java, so we started researching and using Jython.

Jython非常棒,我们正在将Jython解释器导入到Java程序中,以便我们可以访问大多数库.但是,Jython并不完全支持所有功能,而要解决这个问题我们无能为力.所有路径均已正确设置,并且有些模块我们无法导入.

Jython is pretty great, and we are importing the Jython Interpreter into our Java program so that we can access most of the library. However, Jython doesn't quite support everything, and there's not much we can do to get around that. All the paths are set up correctly and there are some modules that we just can't import.

因此,假设我们没有其他办法可以使Python库与Jython兼容,那么下一个想法是以某种方式从Jython解释器中调用Python,并使Python运行一个模块(用Python编写).理想情况下,我们将能够简单地使用Python导入模块,然后使用Jython调用所有方法(但要在Python中执行它们).

So assuming that there's nothing else we can do to make the Python library Jython-compatible, the next idea is to somehow invoke Python from the Jython interpreter, and make Python run a module (written in Python). Ideally, we would be able to simply import the module using Python, and then call all the methods using Jython (but have them executed in Python).

有人知道这是否完全可行吗?

Does anyone know if this is possible at all, and if so how?

推荐答案

您应该可以使用 Pyro 在Jython和CPython之间发送方法调用及其返回数据.它的设计宗旨是对象可以通过网络相互通信",但是没有理由在同一台机器上的两种不同类型的Python之间不能使用相同的技术.

You should be able to use Pyro to send method calls and their return data between Jython and CPython. It's designed so that "objects can talk to each other over the network" but there's no reason the same technique shouldn't work between two different types of Python on a single machine.

在Pyro文档中,您将找到一个简单示例,其中仅显示了有关启动和运行它所需了解的一切.

In the Pyro documentation you will find a simple example which shows you just about everything you need to know to get this up and running.

这篇关于从Jython在Python中运行Python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆