467,927 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,927 developers. It's quick & easy.

jython import search path

I have a Python program that I want to run in Jython so I can get Java
bytecode output. The program runs fine in Python, but when I change
the first line of the main program to make it run in Jython, it fails
to find some of the imported modules. These are just plain Python
imports of code I wrote myself in another directory.

Apparently Jython does not use the PYTHONPATH environment variable. I
created an environment variable called JYTHONPATH just to see what
would happen, but it didn't work either. How am I supposed to tell
Jython where to search for imported modules? Thanks.

Feb 22 '07 #1
  • viewed: 10190
Share:
5 Replies
Russ wrote:
I have a Python program that I want to run in Jython so I can get Java
bytecode output. The program runs fine in Python, but when I change
the first line of the main program to make it run in Jython, it fails
to find some of the imported modules. These are just plain Python
imports of code I wrote myself in another directory.

Apparently Jython does not use the PYTHONPATH environment variable. I
created an environment variable called JYTHONPATH just to see what
would happen, but it didn't work either. How am I supposed to tell
Jython where to search for imported modules? Thanks.
Maybe Jython expert has the perfect answer but til then.

Did you try:

sys.path.append('path to search')

Usually this works if nothing else does.

-Larry
Feb 22 '07 #2
On Feb 21, 4:15 pm, Larry Bates <lba...@websafe.comwrote:
Russ wrote:
I have a Python program that I want to run in Jython so I can get Java
bytecode output. The program runs fine in Python, but when I change
the first line of the main program to make it run in Jython, it fails
to find some of the imported modules. These are just plain Python
imports of code I wrote myself in another directory.
Apparently Jython does not use the PYTHONPATH environment variable. I
created an environment variable called JYTHONPATH just to see what
would happen, but it didn't work either. How am I supposed to tell
Jython where to search for imported modules? Thanks.

Maybe Jython expert has the perfect answer but til then.

Did you try:

sys.path.append('path to search')

Usually this works if nothing else does.

-Larry
Thanks. That's a good workaround, but I would like to know the
"correct" way to do it too if anyone out there knows.

Feb 22 '07 #3
Russ wrote:
On Feb 21, 4:15 pm, Larry Bates <lba...@websafe.comwrote:
>Russ wrote:
I have a Python program that I want to run in Jython so I can get Java
bytecode output. The program runs fine in Python, but when I change
the first line of the main program to make it run in Jython, it fails
to find some of the imported modules. These are just plain Python
imports of code I wrote myself in another directory.
Apparently Jython does not use the PYTHONPATH environment variable. I
created an environment variable called JYTHONPATH just to see what
would happen, but it didn't work either. How am I supposed to tell
Jython where to search for imported modules? Thanks.

Maybe Jython expert has the perfect answer but til then.

Did you try:

sys.path.append('path to search')

Usually this works if nothing else does.

-Larry

Thanks. That's a good workaround, but I would like to know the
"correct" way to do it too if anyone out there knows.
That is pretty much an accepted strategy. Another one is to alter the
registry file, which has a property python.path. It might even be possible
to use

java -Dpython.path=<whatever>

to accomplish that - but I'm to lazy to toy around now.

Diez
Feb 22 '07 #4

Diez B. Roggisch wrote:
Maybe Jython expert has the perfect answer but til then.

Did you try:

sys.path.append('path to search')

Usually this works if nothing else does.

-Larry
Thanks. That's a good workaround, but I would like to know the
"correct" way to do it too if anyone out there knows.

That is pretty much an accepted strategy. Another one is to alter the
registry file, which has a property python.path. It might even be possible
to use
Accepted strategy? It doesn't seem very portable. It assumes that
everyone puts their library
modules in the exact same place. Or do they just figure that changing
the sys.path.append
line is easy enough?
java -Dpython.path=<whatever>
I'm not using Java at all. I just want to generate Java bytecode for
purposes of code analysis
by existing tools.

Feb 22 '07 #5
Accepted strategy? It doesn't seem very portable. It assumes that
everyone puts their library
modules in the exact same place. Or do they just figure that changing
the sys.path.append
line is easy enough?
Portability has nothing to do with it. If you arrange your project in a way
that these paths can be figured out at runtime, it's fine.

If not, you might need some installation routine that will figure them out
when installing the software, hard-coding such paths in some way (as
parameter lists or whatsoever)
>java -Dpython.path=<whatever>

I'm not using Java at all. I just want to generate Java bytecode for
purposes of code analysis
by existing tools.
If you are using jython, you are using java.

Diez
Feb 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by SHELTRAW, DANIEL | last post: by
2 posts views Thread by Joseph Turian | last post: by
reply views Thread by h112211 | last post: by
1 post views Thread by aznach | last post: by
1 post views Thread by mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post: by
3 posts views Thread by SMALLp | last post: by
8 posts views Thread by tow | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.