Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jython does not load PYTHONPATH into sys.path

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__']
like image 591
TravisThomas Avatar asked Jun 06 '13 21:06

TravisThomas


People also ask

Is SYS path same as Pythonpath?

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 .

How does Python set SYS path?

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.

How do I import a module into Jython?

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/…

What is Pythonhome and Pythonpath?

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.


1 Answers

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

like image 144
Salem Avatar answered Sep 24 '22 00:09

Salem