From: Robert W. B. <rb...@di...> - 2001-10-22 19:07:06
|
On Mon, 22 Oct 2001, Ihab A.B. Awad wrote: > Hi all, > > Thanks Robert Bill & Jim Adrig for the tips.... > > > Yes, os requires the javaos module, and you get the ImportError when that > > module cannot be Located. Fix= make sure module is found. > > I've been trying, in every manner possible! Here's my code -- > > rootPath = servletContext.getRealPath("/"); > if (!rootPath.endsWith(File.separator)) rootPath += File.separator; > > Properties p = getInitParametersAsProperties(); > p.put( > "python.cachedir", > servletContext.getAttribute("javax.servlet.context.tempdir").toString()); Maybe try: p.put("python.home", "some/path/that/contains/jython's/Lib/dir") Finding the cachedir will not help jython locate its modules, but finding the correct python.home will. > PythonInterpreter.initialize(System.getProperties(), p, new String[0]); > > PySystemState pySys = Py.getSystemState(); > pySys.add_classdir(rootPath + "WEB-INF" + File.separator + "classes"); > pySys.add_extdir(rootPath + "WEB-INF" + File.separator + "lib"); > pySys.path.append(new PyString(servletContext.getAttribute("python.home") + > File.separator + "Lib")); Maybe try printing python.home to make sure it isn't empty. Actually, printing python.home and sys.path is a good test. > pySys.path.append(new PyString(rootPath + "WEB-INF" + File.separator + > "py")); Are the jython modules in WEB-INF/py/? If javaos.py is there, I'm stumped :( > pythonInterpreter = new PythonInterpreter(null, pySys); > > I think, based on looking at PyServlet.java, that this should get all my > bases covered. Print python.path and python.home to make sure they are correct. That's the easiest way to make sure bases are covered. I would not trust everything is covered until I got a confirmation that the sys.path actually did include the directory that javaos.py lives in. Best of luck. -robert > However, I still get -- > > import os > dir(os) > > Traceback (innermost last): File "", line 10, in ? ImportError: no > module named javaos > > import os > print os.listdir('/home/ihab') > > Traceback (innermost last): File "", line 2, in ? AttributeError: class > 'org.python.modules.os' has no attribute 'listdir' > > This is all very confusing. Any help appreciated from anyone. Peace, |