导入 java ImportError:没有名为 java 的模块

我似乎遇到了障碍,根本无法弄清楚,谁能帮我弄清楚为什么我无法导入 java 模块?

错误:

Traceback (most recent call last):
  File "./datasource_config.py", line 3, in ?
    import java
ImportError: No module named java

爪哇:

13:30:05 # which java
/usr/bin/java

脚本的开头

#!/usr/bin/python
import sys
import java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')

def datasource(cluster,user,password,url,env,jdbc_driver,timeOut,maxConn,minConn,reapTime,unusdTimeout,agedTimeout):

    #Declare global variables 
    global    AdminConfig 
    global    AdminControl

有人可以帮我确定这意味着什么吗?

13:45:07 # ./jython -v /opt/websphere/datasource_config.py
*sys-package-mgr*: can't create package cache dir, '/usr/lib/jython-25/cachedir/packages'
import: 'exceptions' as org.python.core.exceptions in builtin modules
import: 'site' as /usr/lib/jython-25/Lib/site.py
import: 'sys' as sys in builtin modules
import: 'os' as /usr/lib/jython-25/Lib/os.py
import: 'errno' as org.python.modules.errno in builtin modules
import: 'posix' as org.python.modules.posix.PosixModule in builtin modules
import: 'posixpath' as /usr/lib/jython-25/Lib/posixpath.py
import: 'stat' as /usr/lib/jython-25/Lib/stat.py
import: 'Properties' as java class
import: 'FileInputStream' as java class
Traceback (most recent call last):
  File "/opt/websphere/datasource_config.py", line 5, in <module>
    from org.python.modules import time
ImportError: cannot import name time
stack overflow import java ImportError: No module named java
原文答案

答案:

作者头像

该错误在这里具有误导性。问题很可能是您在目录 /usr/lib/jython-25/cachedir/packages 以及父目录 cachedir 中没有权限。如果您在 wsadmin.sh 启动时查看输出的第一行,它实际上暗示了这一点。