I’m trying to do some pretty simple stuff in Jython within Java. My Python path, and by exension, my Jython path, is set to the following:
$ python -c "import sys ; ':'.join(sys.path)"
:/usr/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PIL:/usr/lib/python2.7/dist-packages/gst-0.10:/usr/lib/python2.7/dist-packages/gtk-2.0:/usr/lib/pymodules/python2.7:/usr/lib/python2.7/dist-packages/ubuntu-sso-client:/usr/lib/python2.7/dist-packages/ubuntuone-client:/usr/lib/python2.7/dist-packages/ubuntuone-control-panel:/usr/lib/python2.7/dist-packages/ubuntuone-couch:/usr/lib/python2.7/dist-packages/ubuntuone-installer:/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol:/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode
(An easier to read list can be found here.)
I’ve set my Jython path by defining -Dpython.path=":/usr/lib/python2.7:...", and it’s working fairly well.
I’m experiencing issues, however, whenever I try to do anything significant, like import the os module:
>>> import os
Exception in thread "main" Traceback (most recent call last):
File "<iostream>", line 2, in <module>
SyntaxError: ('no viable alternative at input \'""\'', ('/usr/lib/python2.7/os.py', 754, 18, ' bs = b""\n'))
What’s going wrong here? Is Jython incompatible with Python 2.7? What can I do to get things working?
You cannot mix Python versions and implementations. The Cpython you are using is 2.7 and the Jython is 2.5 so they canot have the same path even if you did this for Cpython 2.5 and 2.7
the actual error you are seeing is because jython loads the python C libraries and gets to code that calls C code which jython does not have.
You can share pure python code that is for the same version e.g. python 2.5 and jython 2.5 but unlikely to manage any other mix.