I figured out something and I want to know the difference between the following two approaches:
(1) I have installed jython and the lastest version of ply (http://www.dabeaz.com/ply/) by running jython.bat setup.py install (which comes with the ply package).
It simply installs the py files inside the 'site-packages' folder.
Then I run the 'calc.py' example which comes with the ply package.
It runs fine. Everything works.
(2) I use Jython in my Java software and I want to use the module lex and yacc (which are part of the ply package).
Here is my code:
public class JythonScriptEngineProvider
public ScriptEngine createEngine(final List<String> pathList)
PySystemState pySystemState = new PySystemState();
for(String path: pathList)
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
The pathList argument can be used to set the python path. And I am using the above class as follows:
List<String> pythonPath = new ArrayList<String>();
pythonPath.add("<my path to the jython lib>");
pythonPath.add("<my path to the jython lib>/site-packages");
ScriptEngine scriptEngine = new JythonScriptEngineProvider().createEngine(pythonPath);
scriptEngine.eval("import ply.lex as lex");
The same error will result when calling the 'calc.py' example like this:
final String pyFile = "C:/DATA/download/ply-3.3/example/calc/calc.py";
scriptEngine.eval(new FileReader(new File(pyFile)));
The error is:
File "<script>", line 1, in <module>
File "C:\DATA\spt_workspace\MEPOtrunk\res\python\site-packages\ply\lex.py", line 887, in lex
ldict = get_caller_module_dict(2)
File "C:\DATA\spt_workspace\MEPOtrunk\res\python\site-packages\ply\lex.py", line 436, in get_caller_module_dict
ldict = f.f_globals.copy()
AttributeError: 'scope' object has no attribute 'copy'
Where is my mistake? What is the problem inside the code. I guess I am doing something completely wrong. But I did not understand it.
Thank you very much