最近更新 :16年3月10日更

首先你在用JAVA,你需要运行Python,于是你找了Jython,我不介绍什么是Jythyon了

如何在Java中调用Python的方法,一百度一大堆,

如下:是一种简单的调用  

  1. PythonInterpreter interpreter = new PythonInterpreter();
  2. InputStream filepy = new FileInputStream("D:\\demo.py");
  3. interpreter.execfile(filepy); ///执行python py文件
  4. filepy.close();
    如果你一不小心遇到了这个错误,那你就来对地方了。

  Determine if the following attributes are correct:
  * sys.path: ['/Users/test/.gradle/caches/modules-2/files-2.1/org.python/jython/2.7.0/576ac65d2cfca511f82f3a65a3568fefd91884d/Lib', '__classpath__', '__pyclasspath__/']
  This attribute might be including the wrong directories, such as from CPython
  * sys.prefix: /Users/test/.gradle/caches/modules-2/files-2.1/org.python/jython/2.7.0/576ac65d2cfca511f82f3a65a3568fefd91884d
  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
  ] with root cause

先说下什么错误意义:

  直译:请确认下面的属性是正确的:

  sys.路径:…………………………(省略了路径)

  这个属性包含了错误的目录,比如CPython

  sys.前缀(其实就是路径的前面一部分):…………(省略了路径)

  这个属性可以通过系统属性python.home设置,通常Jython jar路径路径自动搞定了这个。

  你可以使用-S命令或者设置python.import.site=false设置不引用设定值(根本问题)……好吧,最后这句我理解的不是很好。

然后说一下参考页 面:http://bugs.jython.org/issue2355 对,又是英文

核心是这段话:

  1. hi Soha,
  2. Soha,
  3. I did like this. If you find a better way please share it.
  4. 我不喜欢这个方法,如果你有更好的解决办法,求分享。

  5. 1- Explode the jython jar: get the jython standalone jar, change the .jar to .zip, unzip it into a folder. Inside that unzipped folder you will find a subfolder Lib.
  6. 1-找到Jythonjar 包,获取单独的JythonJar包,将扩展名.jar改成.zip,解压到文件夹,你能在解压后的文件夹里面找到一个Lib文件夹;

  7. 2- Copy that folder Lib into your eclipse project.
    2- 复制这个Lib到你的Eclipse(编译器) 项目
  8. 3- In you java code, when you initialize jython, point to that Lib folder as python.home, for example:
    3- 在你的java代码中华,当你初始化Jython的时候,将python.home设置为这个Lib文件夹,如下
  9. Properties props = new Properties();
    代码没得译
  10. props.put("python.home","path to the Lib folder(你的lib 路径)");
    代码没得译
  11. props.put("python.console.encoding", "UTF-8");
  1. props.put("python.security.respectJavaAccessibility", "false");
    props.put("python.import.site","false");
    Properties preprops = System.getProperties();
    PythonInterpreter.initialize(preprops, props, new String[0]);
    PythonInterpreter interp = new PythonInterpreter();
  2.  
  3. That's it! now it should work!
    然后就可以工作了

然而参考这个并不是全面的,因为并没有Lib(如果你有,我没话说), 解决办法差不多,这个错误的原因,很明确,其实就是找不到Python.home,so代码不变,但是python路径的来源需要你下功夫,上面走的通最好,要么还可以是系统的,也活着干脆你网上下一个随便找个位置解压。OK搞定!!

16-3-2:

如果你实现了上面的步骤,那么恭喜你,基本的运行搞定了,你可以跑简单的python脚本,但是,一个简单的脚本貌似你也没必要大费周章的如此。so,如果你在自己的py中import了系统的或者其他的py,那么,恭喜你炸了!!!!!!

你基本会看到类似下面错误

Exception in thread "main" Traceback (most recent call last):
  File "路径\Test.py", line 4, in <module>
    import odbchelper
ImportError: No module named odbchelper

于是,经过我不断地努力,我想告诉你!!上面的解决办法不够好,之所以出现上面的种种问题,原因在于包上,jython.jar和jython-standalone.jar,目前我尚不清楚这两个包的区别,但是 后者的确会让你避免各种错误,原因我会继续查看并持续更新。

附jar包地址:http://mvnrepository.com/artifact/org.python/jython/2.7.0,包比较大,留下网络地址,你们自己搞吧。

最新更新问题:

使用上面的方法,你的代码应该可以跑了。但是,当你打包的时候,你又会遇到相同的问题,因为,打的包里面它默认又会找之前的路径,但是之前的路径是jar包,于是又炸了

多次探索,最后还是回归,按照上面的提示,使用哪个英文地址的方式,引入一个外面的环境,也就是扔一个Lib放在哪里就好,有问题可以留言,不过最好自己去哪个网址看看,再来一次网址:http://bugs.jython.org/issue2355

 

java or spring +jython +python (Error:python.home,Determine if the following attributes are correct:)的更多相关文章

  1. Python基础-1 python由来 Python安装入门 注释 pyc文件 python变量 获取用户输入 流程控制if while

    1.Python由来 Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚 ...

  2. 在Java中动态传参调用Python脚本

    最近,又接触到一个奇葩的接口,基于老板不断催促赶时间的情况下,在重写java接口和复用已有的python脚本的两条路中选择了后者,但是其实后者并没有好很多,因为我是一个对python的认识仅限于其名称 ...

  3. DES对称加密算法实现:Java,C#,Golang,Python

    数据加密标准(DES,Data Encryption Standard,简写DES)是一种采用块密码加密的对称密钥算法,加密分组长度为64位,其中8.16.24.32.40.48.56.64 等8位是 ...

  4. Python--Cmd窗口运行Python时提示Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: cp65001

    源地址连接: http://www.tuicool.com/articles/ryuaUze 最近,我在把一个 Python 2 的视频下载工具 youku-lixian 改写成 Python 3,并 ...

  5. plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory

    装一台新服务器环境的时候,装uwsgi报错: plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or di ...

  6. deepin 安装scrapy安装出错:fatal error: Python.h 的解决办法

    环境deepin Linux 15.7 Python3.6.5 今天重新装了deepin系统,需要重新安装scrapy,直接pip了一下,没成. 报错:fatal error: Python.h: 没 ...

  7. qingstor python-sdk 安装错误 src/MD2.c:31:20: fatal error: Python.h: No such file or directory

    ubuntu安装python qingstor-sdk, src/MD2.c:31:20: fatal error: Python.h: No such file or directory compi ...

  8. Ubuntu下 fatal error: Python.h: No such file or directory 解决方法

    参考: fatal error: Python.h: No such file or directory Ubuntu下 fatal error: Python.h: No such file or ...

  9. python安装mysqlclient模块报fatal error: Python.h:解决方法

    在搭建Flask框架安装mysqlclient模块时候老是报fatal error: Python.h:错误,折腾老半天,百度了老半天看了不少大神帖子,就是没解决, 后来发现这不是个BUG,都是自己的 ...

随机推荐

  1. VC++文件相关操作的函数封装实现

    在开发编译工具中,需要用到文件的相关操作,于是就封装了相关的函数实现: //判断文件是否存在 BOOL FileIsExist(CString strFileName) { CFileFind fin ...

  2. Java基础知识强化之IO流笔记28:BufferedOutputStream / BufferedInputStream(字节缓冲区流) 之BufferedOutputStream写出数据

    1. BufferedOutputStream / BufferedInputStream(字节缓冲区流)的概述 通过定义数组的方式确实比以前一次读取一个字节的方式快很多,所以,看来有一个缓冲区还是非 ...

  3. a标签中的href="#"与href="javascript:void(0)"区别

    转自http://blog.csdn.net/fightplane/article/details/5190037 <a href="#"> 点击链接后,页面会向上滚到 ...

  4. 需要重新启动计算机.必须重新启动计算机才能安装 SQL Server

    在开始运行中输入regedit找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager 在右边窗口找到PendingFi ...

  5. asp gridview批量删除和全选

    本人新手刚学asp.net   全选和删除也是引用了他人的代码试了一试可以实现,感觉很好,就发了上来. 前台代码 <asp:GridView ID="GridView1" r ...

  6. Oracle 特殊字符模糊查询的方法

    最近在写DAO层的时候,遇到一个问题,就是使用like进行模糊查询时,输入下划线,无法精确查到数据,而是返回所有的数据. 这让我很好奇,百度之后才发现,原来是因为有些特殊字符需要进行转义才可以进行查询 ...

  7. JavaScript+DOM编程艺术【读书笔记】

    第四章笔记: 如何让一个a标签不跳转: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www. ...

  8. Java SE (2)之 Graphics 画图工具

    Graphics 绘图类: 提供两个方法.Paint (绘图,被系统自动调用)    repaint(重绘) Paint 调用原理(1.窗口最大化,再最小化 窗口的大小发生变化 Repaint函数被调 ...

  9. 简单登录案例(SharedPreferences存储账户信息)&联网请求图片并下载到SD卡(文件外部存储)

    新人刚学习Android两周,写一个随笔算是对两周学习成果的巩固,不足之处欢迎各位建议和完善. 这次写的是一个简单登录案例,大概功能如下: 注册的账户信息用SharedPreferences存储: 登 ...

  10. 【转自CSDN】深入 Microsoft.VisualBasic.Strings.StrConv 簡繁轉換

    深入 Microsoft.VisualBasic.Strings.StrConv 簡繁轉換 昨天又遇到一個簡繁轉換的需求, 雖然這個問題以前已經處理過了, 但是以前是用自己建立的 b52gb 和 gb ...