0

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.

0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I did set sys.path. I updated the question, could you have another look?
@Flake sys.path is for Python modules. To load Java code, set up the classpath. Updated the answer.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.