Title: Django - modjy doesn't recognise lib-python/* sub folders
Type: behaviour Severity: minor
Components: Library Versions: 2.5b0
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: amak Nosy List: JohnSJohnM, amak, cgroves, leosoto
Priority: Keywords:

Created on 2009-01-08.13:57:54 by JohnSJohnM, last changed 2009-01-26.08:28:39 by JohnSJohnM.

msg4015 (view) Author: JohnSJohnM (JohnSJohnM) Date: 2009-01-08.13:57:53
As noted here (
via-jython.html under point 6.), when a packaged up application is 
deployed to an application server utilising modjy it does not pick up 
any additional Python libraries which have been included in your 

For example in my test Django app, under:


.. I have 'Lib', 'doj', 'django' and 'LSE_PublicSite' sub folders which 
are not searched, thus making it pretty difficult for any application 
to run.

As detailed in the blog, above, by manually adding a .pth file for each 
sub folder their contents are available on the path again. 
Could this be automated?

This is tested with modjy 0.25.1, but also has been the case with 
several prior versions I have tested.
msg4017 (view) Author: Charlie Groves (cgroves) Date: 2009-01-10.12:43:08
As of 2.5b1, Jython can import .py and compiled .py files from the
classpath.  By default it uses paths without any prefix on the classpath
to find items, so your python modules would have to be in a jar or
directory or the classpath without any intervening directories if you
want to use it without messing with sys.path.  If you'd rather leave
things in lib-python, add '__pyclasspath__/lib-python' to sys.path, and
Jython will start looking for modules in lib-python on the classpath.
msg4023 (view) Author: Alan Kennedy (amak) Date: 2009-01-10.19:42:15
This is a mis-understanding; modjy does not recognise sub-folders of
lib-python. Modjy requires that you add dub-directories or
jars/eggs/zips to .pth files; this is documented in the modjy documentation.

I wrote up the details on that blog post you mentioned, as a comment. I
repeat those comments here.

#6: Subdirectories of lib-python.

Initially, when Leo was developing Django-on-Jython, he adopted the
convention of adding every subdirectory of lib-python to sys.path.
However, this was not a clean solution, because it required that actual
libraries be stored two subdirectories down, e.g. "django" would be
stored in "lib-python/django/django", which was counter-intuitive.

So I adopted a different solution for modjy, which was to add only the
lib-python directory to sys.path. This means that django, for example,
would be stored directly under lib-python/django; no deeper
subdirectories required.

The reason why Leo adopted his original convention was that ".egg",
".jar" file, etc, would be also be added to sys.path, being entries in
the lib-python directory.

This was a good solution to the problem, but I thought it better to use
the standard python convention of .pth files. Listing .eggs, .jars and
.zips in .pth files was more explicit (remember "explicit is better than
implicit"), and also standard.

The .pth solution is what is explicitly stated in the modjy
documentation, so the statement "According to modjy, it added to the
python path every subdirectory of WEB-INFO/lib-python in the .war. But
it turns out, after peeking in the code, that this is not actually the
case." The actual case is what is documented, and not otherwise.

Lastly, you should not need a single .pth file for every library or
directory; you can use a single .pth file, perhaps "all.pth", which
lists every path you want added to sys.path. So all.pth could look like this

msg4029 (view) Author: JohnSJohnM (JohnSJohnM) Date: 2009-01-12.08:47:24
Presuming Django does eventually get working cleanly on the current 
Jython, along with Modjy + Tomcat/Glassfish/etc environment this is 
still a barrier to be able to cleanly deploy such applications as WAR 
files due to the need to manually add these auto-generated sub folders 
to sys.path.

As such, do you think this is better suited to be patched within Django-
jython, so that the suggested 'all.pth' is auto-created at WAR file 
msg4074 (view) Author: Leonardo Soto (leosoto) Date: 2009-01-25.18:03:14
Please try the modjy-0.25-integration branch[1] of django-jython. There
I've fixed this problem, and testing is always welcomed

msg4081 (view) Author: JohnSJohnM (JohnSJohnM) Date: 2009-01-26.08:28:38
Thanks Leonardo, hopefully I'll get time to test the latest versions 
this week.
Date User Action Args
2009-01-26 08:28:39JohnSJohnMsetmessages: + msg4081
2009-01-25 18:03:14leosotosetnosy: + leosoto
messages: + msg4074
2009-01-12 08:47:26JohnSJohnMsetmessages: + msg4029
2009-01-10 19:42:17amaksetstatus: open -> closed
assignee: amak
resolution: invalid
messages: + msg4023
nosy: + amak
2009-01-10 12:43:09cgrovessetnosy: + cgroves
messages: + msg4017
2009-01-08 13:57:54JohnSJohnMcreate