Java执行Python代码报错console: Failed to install java.nio.charset.UnsupportedCharsetException: cp0
来源:互联网 发布:linux下一行 编辑:程序博客网 时间:2024/06/06 06:52
代码:
PythonInterpreter interpreter = new PythonInterpreter(); interpreter.execfile("D:\\softwares\\pycharm\\untitled2\\test.py");
报错信息:
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
Exception in thread "main" ImportError: Cannot import site module and its dependencies: No module named siteDetermine if the following attributes are correct:
* sys.path: ['D:\\.m2\\repository\\org\\python\\jython\\2.7.0\\Lib', '__classpath__', '__pyclasspath__/']
This attribute might be including the wrong directories, such as from CPython
* sys.prefix: D:\.m2\repository\org\python\jython\2.7.0
This attribute is set by the system property python.home, although it can
be often automatically determined by the location of the Jython jar file
You can use the -S option or python.import.site=false to not import the site module
在代码中添加:
Properties props = new Properties(); props.put("python.console.encoding", "UTF-8"); props.put("python.security.respectJavaAccessibility", "false"); props.put("python.import.site", "false"); Properties preprops = System.getProperties(); PythonInterpreter.initialize(preprops, props, new String[0]); PythonInterpreter interpreter = new PythonInterpreter(); interpreter.execfile("D:\\softwares\\pycharm\\untitled2\\test.py");
这样就不会报错了。
0 0
- Java执行Python代码报错console: Failed to install java.nio.charset.UnsupportedCharsetException: cp0
- java调python报错console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
- jython在eclipse控制台出现Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0解决方法
- jython在eclipse控制台出现Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0解决方法
- bug宝典JAVA篇 java.nio.charset.UnsupportedCharsetException: cp0
- Java NIO--Charset
- Android 工程运行报错 Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOv
- scala:java.nio.charset.MalformedInputException
- JAVA学习5_Java NIO 报java.nio.charset.MalformedInputException: Input length = 1异常
- NIO中,java.nio.charset.MalformedInputException
- hive运行报Call to master/**.** failed on local exception: java.nio.channels.ClosedByInterr
- 我的Java开发学习之旅------>Java NIO 报java.nio.charset.MalformedInputException: Input length = 1异常
- 运行报错:Unable to execute dex: java.nio.BufferOverflowException
- flume报java.nio.charset.MalformedInputException: Input length = 1 解决方案
- 读文件异常:java.nio.charset.MalformedInputException
- Java NIO中Charset类源码
- 利用java.nio.charset.CharsetDecoder自动识别字符集
- 利用java.nio.charset.CharsetDecoder自动识别字符集
- 【考研】考后总结
- 从源代码分析Android-Universal-Image-Loader的缓存处理机制
- oracle中存储 过程嵌套游标的使用
- Android Studio 中 build下clean 和rebuild选项消失
- [hihocoder taige 20-1]括号配对
- Java执行Python代码报错console: Failed to install java.nio.charset.UnsupportedCharsetException: cp0
- 检测点2.2
- CSS 的初识
- 解决Oracle安装使用中文乱码问题
- Httpclient
- POJ 1185 炮兵阵地(dp+状压)
- node环境搭建
- JavaScript 焦点事件
- ListView 与ViewHolder