Flake
Flake

Reputation: 4497

How to invoke Jython interpreter from python source code in Windows

Stated here, one can invoke Jython in source code in Unix platforms.

I've installed Jython and put the directory in PATH in windows.

How could I set this up to invoke Jython from .py code automatically? Thanks.


Make the example more specific and clear:

#!/usr/bin/env jython
import sys
sys.path.append("./package.jar")
import org.abc.name

ImportError: No module named org.abc.name

And if I run Jython bar.py from cmd, it did work. But running Python bar.py fails with the error.

Upvotes: 0

Views: 469

Answers (2)

Giacomo Lacava
Giacomo Lacava

Reputation: 1823

Your jar path is relative. Under Jython, the base path for the script is calculated in a different way than under CPython.

I bet that it would have worked from the beginning if you just added the full path to the jar to sys.path rather than the relative one.

Upvotes: 0

phihag
phihag

Reputation: 287865

An ImportError is already a Python error, so it looks like jython is working. You need, however, to set up the path.

If xxx stands for one of your Python modules, set up sys.path to contain the appropriate directory before importing it.

If xxx stands for one of your Java modules, set up the Java Classpath to contain the appropriate directory or jar.

If xxx stands for a built-in module, it is probably not supported by jython yet. Have a look at the list of modules supported by jython. Some newer modules that are available on other Python platforms (such as json) are not yet available in jython.

Upvotes: 2

Related Questions