esnet / netshell

Kernel and companion software that support ENOS applications (NOT ACTIVELY MAINTAINED)
Other
6 stars 1 forks source link

netshell-python doesn't find Python libraries #3

Closed bmah888 closed 8 years ago

bmah888 commented 9 years ago

Stumbled upon by @lomaxfrog:

Jython ships with a number of Python libraries, such as the json library. For some reason, the jython-standalone bundle (Jython 2.7b4) can't find them, even though they're in the JAR in the Lib/ directory. We should be able to solve this by adding __pyclasspath__/Lib to sys.path like this:

sys.path = sys.path + ['__pyclasspath__/Lib']

But this doesn't work.

bmah888 commented 9 years ago

I'm stumbling into this problem and would like a solution. These bugs appear related to this one:

http://bugs.jython.org/issue2143 http://bugs.jython.org/issue2149

The text of these bugs imply that finding stuff in the JAR's Lib/ directory actually does work, however.

bmah888 commented 9 years ago

Here's a workaround (that I think is better than what @lomaxfrog and I discussed, because it doesn't require unpacking the JAR file to the local filesystem)...put these lines in init.py:

# Fix for not having $JARFILE/Lib in path
from org.python.util import jython
# We should really do os.path.join(jython()..., 'Lib') here but we can't
# import os;
sys.path.append(jython().getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + '/Lib')
lomaxfrog commented 8 years ago

With the lastest changes, I believe this issue has became a non issue. Bruce would you agree ?