导入 java 导入错误:没有名为 java 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21612235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import java ImportError: No module named java
提问by Blogger11
I seemed to have hit a roadblock and can't figure this out at all, can anyone help me figure out why I am unable to import the java module?
我似乎遇到了障碍,根本无法解决这个问题,谁能帮我弄清楚为什么我无法导入 java 模块?
Error:
错误:
Traceback (most recent call last):
File "./datasource_config.py", line 3, in ?
import java
ImportError: No module named java
java:
爪哇:
13:30:05 # which java
/usr/bin/java
beginning of script
脚本开头
#!/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
Can someone help me determine what this means?
有人可以帮我确定这是什么意思吗?
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
回答by skymoose
The error is misleading here. The problem is likely to be that you dont have permissions in directory /usr/lib/jython-25/cachedir/packages and possibly the parent directory cachedir too. If you look at the first line of the output when wsadmin.sh starts, it actually implies this.
这里的错误具有误导性。问题很可能是您在目录 /usr/lib/jython-25/cachedir/packages 中没有权限,也可能在父目录 cachedir 中没有权限。如果您查看 wsadmin.sh 启动时输出的第一行,它实际上暗示了这一点。