According to what I've read, sys.path should be set by PYTHONPATH. In Python, it works that way, but not in Jython. I can circumvent with -Dpython.path=...
but I'd like to know why Jython isn't playing nicely.
qa@Scantron:/tmp/pip-build-qa/robotframework> echo $PYTHONPATH
/usr/lib64/python2.7
qa@Scantron:/tmp/pip-build-qa/robotframework> jython
Jython 2.2.1 on java1.7.0_17
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/share/jython/Lib', '__classpath__']
>>> ^D
qa@Scantron:/tmp/pip-build-qa/robotframework> jython -Dpython.path=/usr/lib64/python2.7
Jython 2.2.1 on java1.7.0_17
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/share/jython/Lib', '/usr/lib64/python2.7', '__classpath__']
PYTHONPATH is related to sys. path very closely. PYTHONPATH is an environment variable that you set before running the Python interpreter. PYTHONPATH , if it exists, should contain directories that should be searched for modules when using import .
sys. path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module. When a module(a module is a python file) is imported within a Python file, the interpreter first searches for the specified module among its built-in modules.
You can do the easy_install for jython. Then next time you startup jython you will be able to import it. The official docs are here: jython.org/jythonbook/en/1.0/…
PYTHONPATH can be set to point to additional directories with private libraries in them. PYTHONHOME sets the location of default libraries. Documentation: PYTHONHOME. Change the location of the standard Python libraries.
Jython does not use PYTHONPATH: you can see here a discussion.
From 2.5 onwards there is a variable that does the same: JYTHONPATH. Before that you can use the trick you already know.
Source: Jython and PYTHONPATH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With