在eclipse中用java调用python报错 Exception in thread "main" ImportError: Cannot import site module and its dependencies
最近做项目需要用java调用python,配置了jython后,运行了例子代码:
获得一个元组里面的元素:
import org.python.util.PythonInterpreter;
public class FirstJavaScript {
public static void main(String args[]) { PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days[1];"); }// main
}
运行时报错:
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: ['C:\\(你的项目地址)', '__classpath__', '__pyclasspath__/']
This attribute might be including the wrong directories, such as from CPython
* sys.prefix: C:(你的项目地址)
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.home", "path to the Lib folder");
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.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days[1];");
执行结果是Tue
在eclipse中用java调用python报错 Exception in thread "main" ImportError: Cannot import site module and its dependencies的更多相关文章
- java使用类数组 报错Exception in thread "main" java.lang.NullPointerException
源代码如下: Point[] points=new Point[n];//Point是一个类 for(int i=0;i<n;i++) { System.out.print("请输入x ...
- Spring Boot 启动报错 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 37
使用命令 java -jar springBoot.jar 启动项目,结果报错如下: Exception at java.lang.String.substring(String.java:) at ...
- Idea运行时Scala报错Exception in thread "main" java.lang.NoSuchMethodError:com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
一.情况描述 使用idea +scala+spark,运行程序代码如下: package cn.idcast.hello import org.apache.spark.rdd.RDD import ...
- xom报错 Exception in thread "main" java.net.UnknownHostException: file
Exception in thread "main" java.net.UnknownHostException: file at java.net.AbstractPlainSo ...
- 创建Sqoop作业,报错Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P in ...
- 使用IntelliJ工具打包kotlin为bat文件运行报错 Exception in thread "main" java.lang.NoClassDefFoundError
Exception in thread "main" java.lang.NoClassDefFoundError 这个很有可能是因为idea里的java版本与电脑上的java环境 ...
- MyBatis笔记----报错Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectUser
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@41cf53f9: startup ...
- Spring报错:Exception in thread "main" java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.<init>(Unknown Source)
简单搭建了一个Spring Maven工程就报错: 看到网上说是JDK 7 和 Spring3.x :JDK编译级别设置成1.7,仍然没有得到解决,采用版本为 3.2.0.RELEASE <b ...
- 使用Grizzy+Jersey搭建一个RESTful框架()报错Exception in thread "main" java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
报错的类涉及UriBuilder,我搜索类发现, 这个类存在于两个包中,我在baidu的时候,也有人提到是jar包冲突,我就删除了 这个依赖,问题解决了. 环境搭建过程请见地址https://blog ...
随机推荐
- 2018-10-19-jekyll-添加-Valine-评论
title author date CreateTime categories jekyll 添加 Valine 评论 lindexi 2018-10-19 09:10:40 +0800 2018-2 ...
- [vue/no-parsing-error] Parsing error: x-invalid-end-tag.eslint-plugin-vue
[vue/no-parsing-error] Parsing error: x-invalid-end-tag.eslint-plugin-vue 解决方案:vscode里面选择设置->搜索 ...
- 【重学Node.js 第4篇】实现一个简易爬虫&启动定时任务
实现一个简易爬虫&启动定时任务 课程介绍看这里:https://www.cnblogs.com/zhangran/p/11963616.html 项目github地址:https://gith ...
- 【题解】BZOJ4241: 历史研究(魔改莫队)
[题解]BZOJ4241: 历史研究(魔改莫队) 真的是好题啊 题意 给你一个序列和很多组询问(可以离线),问你这个区间中\(\max\){元素出现个数\(\times\)元素权值} IOI国历史研究 ...
- $vjudge\ CSP-S$专题专练题解
照例先放个链接$QwQ$ $A$ $QwQ$之前写过题解辣. 重新说下趴,就给横坐标纵坐标也开点,然后每个点连向对应横纵坐标边权为$0$,相邻横坐标点之间连边,相邻纵坐标点之间连边,跑个最短路就完事$ ...
- 分享在开发多终端使用比较多的Adb命令
分享在开发多终端或者涉及PC-Android的传输使用比较多的Adb命令 查看连接的设备 adb devices 列出设备安装的软件包 adb shell pm list packages 使用这个方 ...
- Web漏洞总结: OWASP Top 10
本文原创,更多内容可以参考: Java 全栈知识体系.如需转载请说明原处. 开发安全 - OWASP Top 10 在学习安全需要总体了解安全趋势和常见的Web漏洞,首推了解OWASP,因为它代表着业 ...
- React实现座位排布组件
React实现座位排布组件 最近在开发一个影院系统的后台管理系统,该后台可以设置一个影厅的布局. 后台使用的是react框架,一位大神学长在几天之内就把这个控件研究出来了,并进行了较为严密的封装,佩服 ...
- K8s 实践 | 如何解决多租户集群的安全隔离问题?
作者 | 匡大虎 阿里巴巴技术专家 导读:如何解决多租户集群的安全隔离问题是企业上云的一个关键问题,本文主要介绍 Kubernetes 多租户集群的基本概念和常见应用形态,以及在企业内部共享集群的业 ...
- [白话解析] 深入浅出 极大似然估计 & 极大后验概率估计
[白话解析] 深入浅出极大似然估计 & 极大后验概率估计 0x00 摘要 本文在少用数学公式的情况下,尽量仅依靠感性直觉的思考来讲解 极大似然估计 & 极大后验概率估计,并且从名著中找 ...