Jython 2.5.1: "ImportError: No Module named os"

Leonidas picture Leonidas · Oct 28, 2009 · Viewed 16.1k times · Source

I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).

I'm running a script that uses the threading.py class. At some point the statement "import os" is evaluated from linecache.py and I get this error, which I can't seem to figure out how to fix:

'Execution failed.  Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "../lib/python/threading.py", line 6, in <module>
 import traceback
 File "../lib/python/traceback.py", line 3, in <module>
 import linecache
 File "../lib/python/linecache.py", line 9, in <module>
 import os
 ImportError: No module named os'

Answer

jitter picture jitter · Oct 28, 2009

What do you mean with "the jar that comes with the 2.5 download"? Did you extract the contents and use jython.jar or did you run the installer? If you just extracted and didn't run the installer your jython.jar will miss the whole LIB folder.

Can you check if jython.jar contains a LIB folder? (e.g. open jython.jar with 7z or WinZip).

Or try copying the LIB folder in the same folder where jython.jar resides.


Did you try setting these properties. Jython Registry. e.g. via -Dpython.home in the eclipse run configuration.

python.cachedir
python.path
python.home

How is the jar named? If similar to jython-complete.jar try renaming it to jython.jar