我有一个python脚本,我想用java运行。
当我跑的时候,它在终端工作得很好
$python/Users/myuser/Projects/hgvs/hgvs/tests/test\gsg_变量.py在
目前我有这个:
Process p = Runtime.getRuntime().exec("python /Users/afrieden/Projects/hgvs/hgvs/tests/test_gsg_variants.py");
String s = null;
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
我得到的输出是:
^{2}$以下是命令的标准错误(如果有):
Traceback (most recent call last):
File "/Users/afrieden/Projects/hgvs/hgvs/tests/test_gsg_variants.py", line 2, in <module>
import hgvs
ImportError: No module named hgvs
Process finished with exit code 0
为什么找不到这个进口?在
编辑:系统列表现在是相同的,导入错误已经消失。在终端python中工作得很好,但是当我按照相同的代码使用java执行系统调用时,就会失败。在
/Users/afrieden/Projects/hgvs/hgvs/tests
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygr-0.8.2-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc-3.0.7-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
/Library/Python/2.7/site-packages
/Users/afrieden/Projects/hgvs/build/lib/
/Users/afrieden/pythonLib/pygr-0.8.2/
/Users/afrieden/pythonLib/pygr-0.8.2/pygr/seqfmt.pyx
/Users/afrieden/pythonLib/pygr-0.8.2/pygr/seqfmt.c
但是,我现在在java系统调用中得到了这个错误:
以下是命令的标准错误(如果有):
Traceback (most recent call last):
File "/Users/afrieden/Projects/hgvs/hgvs/tests/test_gsg_variants.py", line 24, in <module>
genome = SequenceFileDB('/Users/afrieden/test/hg/hg18.fa')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygr-0.8.2-py2.7-macosx-10.6-intel.egg/pygr/seqdb.py", line 424, in __init__
seqLenDict = classutil.open_shelve(fullpath, 'r')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygr-0.8.2-py2.7-macosx-10.6-intel.egg/pygr/classutil.py", line 457, in open_shelve
return dbfile.shelve_open(filename, flag=mode, useHash=useHash)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygr-0.8.2-py2.7-macosx-10.6-intel.egg/pygr/dbfile.py", line 167, in shelve_open
d = open_index(filename, flag, useHash, mode) # construct Shelf only if OK
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygr-0.8.2-py2.7-macosx-10.6-intel.egg/pygr/dbfile.py", line 106, in open_index
d = open_anydbm(filename, flag)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygr-0.8.2-py2.7-macosx-10.6-intel.egg/pygr/dbfile.py", line 46, in open_anydbm
raise WrongFormatError(msg)
pygr.dbfile.WrongFormatError: db type could not be determined
有什么想法吗?在
我使用了另一种方法jython
我想这会对你有所帮助,除非档案的权利不对。在
我建议您使用完整的python exec路径,例如
并检查上述文件的权限。它需要任何其他人都可以执行。比如755。我不知道这对你有没有帮助,但试试看。在
相关问题 更多 >
编程相关推荐