loading of modules in jython 2.1 !?
Nicolas Duchastel
nicolas at otelnet.com
Mon Jul 15 14:40:19 EDT 2002
3 questions about how to start JYTHON and where it reads module from.
Any help would be greatly welcomed.
I tried the FAQs and other resources and I never found anything.
P.S. adding this to FAQ would be great: i.e. the reason I am posting
now is that I often get these kinds of problems and always end-up
trying a zillion things and "mysteriously" fixing it. I never
understand why and how it got fixed (e.g. some times I simply
copy a bunch of files to my local dir!!), and I am pretty sure
that I am not the only one out there (i.e. cry for help! :))
Thanks,
Nicolas
--------------------------------
QUESTION:
========
1- why is my local registry file (e.g. ~/.jpython) not read when I
start script as:
jython myfile.py
but it does work if I do:
./myfile.py
2- when is the CLASSPATH (or PYTHONPATH) env variables used by
jython; if it is ever used !?
3- why do I get different results depending if I start script directly
or by 1st calling jython !?
e.g. "jython myfile.py" is different than "./myfile.py"
DETAILS
=======
I have a jython file called: myTestCase.py. It is executable and has as it's
first line of text:
#! /usr/bin/env/ jpython
It use a bunch of utilities that we have written; these are all found
under some directory called /export/home7/Tools/CSP/train/OTelCORE/lib:
e.g. util.py (yeah! I know, its not a great name! :))
results.py
...
I have different behaviours based on how I call this script; and I don't
know why. Can anyone help.
a) ./myTestCase.py -> doesn't work
Traceback (innermost last):
File "./myTestCase.py", line 12, in ?
File "/export/home7/Tools/CSP/train/OTelCORE/lib/util.py", line 8, in ?
AttributeError: java package 'org.apache' has no attribute 'oro'
that's because util.py has line 8 which reads:
from org.apache.oro.text.regex import *
I then add the path to my Jython 2.1 distribution and I now get another
error:
Traceback (innermost last):
File "./1.2-sendOneMsg.py", line 12, in ?
File "/export/home7/Tools/CSP/train/OTelCORE/lib/util.py", line 8, in ?
TypeError: can not dir a java directory package
I have a ~myuser/.jpython file which has the proper "python.path" stuff
to point to /export/home7/.../lib. I know that this file is read since
when I change another property such as "python.verbose", the display
does change!!
b) if I try by using jython directly -> does work, but needs lots of work!
i.e. jython ./myTestCase.py
it first complains that it can't find 'results.py': i.e. that's a module
which was loaded BEFORE util.py!!! It worked before!!
import: 'results' not found (ImportError)
Traceback (innermost last):
File "1.2-sendOneMsg.py", line 10, in ?
ImportError: no module named results
It seems that this time around my registry information at ~myuser/.jpython
is completely ignored (i.e. I don't get the verbose stuff on the display).
WHY IS THAT !?
Anyway, if I had the extra dir to my classpath:
setenv CLASSPATH "${CLASSPATH}:/export/home7/..../lib"
I still get the same thing! i.e. can't find the results.py (or the util.py
I would guess) even though the previous one did !!
The only way I get it to work is if I do:
jython -Dpython.path=/export/home7/Tools/.../lib ./myTestCase.py
More information about the Python-list
mailing list