Java执行Python代码报错console: Failed to install java.nio.charset.UnsupportedCharsetException: cp0
2016-12-27 19:30
726 查看
代码:
报错信息:
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
Exception in thread "main" ImportError: Cannot import site module and its dependencies: No module named site
Determine 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
在代码中添加:
这样就不会报错了。
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 site
Determine 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");
这样就不会报错了。
相关文章推荐
- 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解决方法
- java.nio.charset.UnsupportedCharsetException: cp0
- bug宝典JAVA篇 java.nio.charset.UnsupportedCharsetException: cp0
- Android 报错:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
- Error处理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException
- IDEA错误:Failed to start end point associated with ProtocolHandler [http-nio-9999] java.net.BindException: Address already in use: bind
- Error处理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- 转 Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- Error处理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- Error处理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- Error occurred during initialization of VM due to java.nio.charset.IllegalCharsetNameException
- elasticsearchException:Failed to load logging configuration Caused by: java.nio.file.NoSuchFileExcep
- Error处理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- 使用TextInputLayout所遇到的坑-java.lang.UnsupportedOperationException: Failed to resolve attribute at index
- Error处理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.
- [置顶] 编译Android项目的时候报错Unable to execute dex: java.nio.BufferOverflowException. 解决方案