[request] sys.path should include PYTHONPATH environment variable (or JYTHONPATH if available)

Bug #1312239 reported by Sandair
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

current state for version 1.1.0:
- PYTHONPATH is ignored
- JYTHONPATH is used if specified and overwrites -Dpython.path which is used if present

still to do
- .pth files should be recognised as well (if in JYTHONPATH/site-packages)

in any case:
import org.sikuli.script.SikulixForJython
(or deprecated: import org.sikuli.basics.SikulixForJython)
takes care, that sikulixapi.jar/Lib gets sys.path[0]

------------------------

available now in 1.1.0 2014-09-17+
in sys.path at script runtime

OS environment PYTHONPATH variable with one or more paths separated by : or ; respectively.
--------------------------------------------------------
If I want to import Python scripts without manually setting sys.path beforehand (as in an automated testing environment), I set the environment variable PYTHONPATH to where the scripts to be imported are, and sys.path will include these paths.

But that does not happen for Sikuli scripts: os.environ["PYTHONPATH"] is set properly with my paths, but sys.path does not include them.

Windows 7, 64 bit
Sikuli 1.0.1

description: updated
RaiMan (raimund-hocke)
summary: - sys.path does not include PYTHONPATH environment variable
+ [request] sys.path should include PYTHONPATH environment variable
Changed in sikuli:
status: New → Fix Committed
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
RaiMan (raimund-hocke)
Changed in sikuli:
importance: High → Critical
description: updated
Revision history for this message
Ryan (ryan-pisano) wrote : Re: [request] sys.path should include PYTHONPATH environment variable

Should this be PYTHONPATH or JYTHONPATH? I would assume JYTHONPATH since Jython itself does not use the PYTHONPATH variable. I believe this was done because not all modules are compatible with both interpreters.

In my project I used the JYTHONPATH to specify the location of the Jython top level packages (I do not want to mix Jython and CPython packages since our framework uses both and neither is compatible with the other interpreter) and sikuli is able to find them. I confirmed this by first opening a Jython interactive session and verifying using help('modules') to verify my package was available. I then used a sikuli interactive session from sikuli-script.jar to print the modules again and they are the same.

I can open a new defect if necessary, but a related issue is the use of a .pth file verified in the same way. When we deploy our execution lab machines we are planning on setting the module paths via a .pth file (one for Python and a separate one for Jython) so it can be updated without changing the system configuration. When the file is included in the Jython site-package folder I can create a Jython interactive session and use help('modules') and see all of the JYTHONPATH modules, as well as the modules in my .pth file. When I do the same through the sikuli interactive session I am missing the files outlined in the .pth file.

Revision history for this message
RaiMan (raimund-hocke) wrote :

@Ryan
Uuups, thanks for the pointer.
absolutely right.

I will fix that and have a look at the .pth file feature (did not know that until now).

Do you have some doc pointer for me or a simple example?

summary: - [request] sys.path should include PYTHONPATH environment variable
+ [request] sys.path should include PYTHONPATH environment variable (or
+ JYTHONPATH if available)
Changed in sikuli:
importance: Critical → High
description: updated
Revision history for this message
Ryan (ryan-pisano) wrote :

No problem. I will create a simple test scenario below showing the issue and attach a zip with the docs.

(assuming windows)
1. Move "aModuleBeginningWithA.py" to c:\newMod
2. Place addMod.pth to the Lib/site-package directory
3. Create an interactive Jython session and use the command help('modules')
3. --aModuleBeginningWithA.py should be one of the first modules listed (mine was after the modules beginning with "_")
4. Create an interactive sikuli session( I used "java -jar sikuli-script.jar -I" in the sikuli folder to replicate our automation)
5. Use the command help('modules')
5. --Verify that aModuleBeginningWithA is one of the first modules (Mine was after the modules beginning with "_")

I have some supporting documentation for the .pth file behavior:
https://docs.python.org/2/library/site.html

Revision history for this message
Ryan (ryan-pisano) wrote :

I should add (Not sure how to edit my last comment) that the behavior should be the same for Jython.

The Jython specific documentation is here (should be the same):
http://www.jython.org/docs/library/site.html

Revision history for this message
RaiMan (raimund-hocke) wrote :

great. thanks.

I will analyze the situation the next days and fix what is needed.

RaiMan (raimund-hocke)
description: updated
description: updated
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 1.1.0 → 2.0.0
importance: High → Medium
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 2.0.0 → 2.1.0
status: Fix Committed → In Progress
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.