Home > Back-end >  The JAVA with jypthon call python error, to the great god help!!!!!!
The JAVA with jypthon call python error, to the great god help!!!!!!

Time:09-15

In recent days the boss wants me to write a python crawler, delving into finally small has becomes a few days, just as I was ready to dacheng, download the jython with no, has been an error (the following code, copy online for the demo), I was using a MAC, installed prdev plug-ins eclipse IDE, python3.6, jython2.7, now have a few questions, hope to understand in the BBS of great god help me, thank you!
1 version of incompatible problems
2 MAC jypthon didn't installed in terminal input jython, no reaction
3 eclispse isn't set up less what, especially on the compiler

 
Properties props=new Properties();
Props. The put (python. The console. "encoding", "utf-8");
Props. The put (" python. Security. RespectJavaAccessibility ", "false");
Props. The put (python. Import. "site", "false");
The Properties of preprops=System. The getProperties ();

PythonInterpreter. The initialize (preprops, props, new String [0]).
PythonInterpreter interpreter=new PythonInterpreter ();
Interpreter. The exec (" import sys ");
Interpreter. The exec (" sys. Path. Append ('/Users/zhong/jython2.7.0/Lib ') ");//jython own
Interpreter. The exec (" sys. Path. Append ('/Users/zhong/jython2.7.0/Lib/site - packages') ");//load jython script Python jar package

Interpreter. Execfile ("./pythonProfile getPython1. Py ");
PyFunction func=(PyFunction) interpreter. Get (" adder, "PyFunction. Class);
Int a=10, b=2;
PyObject pyobj=func. __call__ (new PyInteger (a), the new PyInteger (b));
System. The out. Println (" anwser="+ pyobj. ToString ());



 the Exception in the thread "is the main" Java. Lang. IllegalArgumentException: always create a PyString with non - byte value 
The at org. Python. Core. PyString. & lt; init> (PyString. Java: 64)
The at org. Python. Core. PyString. & lt; init> (PyString. Java: 70)
The at org. Python. Core. PySyntaxError. & lt; init> (PySyntaxError. Java: 33)
The at org. Python. Core. ParserFacade. FixParseError (ParserFacade. Java: 95)
The at org. Python. Core. ParserFacade. Parse (ParserFacade. Java: 190)
At org.python.core.Py.com pile_flags (Py. Java: 1956)
The at org. Python. Core. __builtin__. Execfile_flags (__builtin__. Java: 527)
The at org. Python. Util. PythonInterpreter. Execfile (PythonInterpreter. Java: 286)
The at test1. Python_Java. Main (Python_Java. Java: 46)


Looking at online call is successful, I here is not used, the

CodePudding user response:

Java is a unicode string inside, python to byte string

CodePudding user response:

reference 1st floor oyljerry response:
Java is a unicode string inside, python to byte string

That I'm going to turn a JAVA string into a byte in the past? To say the detailed point? thank you

CodePudding user response:

refer to the second floor sixgod_zhong response:
Quote: refer to 1st floor oyljerry response:

Java is a unicode string inside, python to byte string

That I'm going to turn a JAVA string into a byte in the past? To say the detailed point? Thank you

Yes, need to change my,

CodePudding user response:

Pilot good package jython. Jar

Use new pyString (string);
  • Related