Issue1318

classification
Title: cannot use __future__ in files executed with PythonInterpreter.execfile
Type: Severity: major
Components: Core Versions: 2.5b0
Milestone:
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: doublep, otmarhumbel
Priority: Keywords:

Created on 2009-04-16.13:25:45 by doublep, last changed 2009-04-20.12:46:14 by doublep.

Files
File name Uploaded Description Edit Remove
LibImportTest.java otmarhumbel, 2009-04-20.11:08:54 java main program
test_lib_import.py otmarhumbel, 2009-04-20.11:09:50
LibImportTest.sh otmarhumbel, 2009-04-20.11:15:37 sample shell script to start the test in different ways
Messages
msg4520 (view) Author: (doublep) Date: 2009-04-16.13:25:44
When a file executed with PythonInterpreter.execfile (InputStream,
String) contains the following line at the top:

    from __future__ import with_statement

I get this error:

    ImportError: No module named __future__

If this is executed using the standalone JAR, it works fine.

Maybe there is some other way to enable "future" features when running
scripts this way (i.e. with PythonInterpreter), but then I couldn't find
those.
msg4546 (view) Author: Oti Humbel (otmarhumbel) Date: 2009-04-20.11:09:50
.py file containing the import statement
msg4547 (view) Author: Oti Humbel (otmarhumbel) Date: 2009-04-20.11:15:37
As the attached sample shell script demonstrates, simply copying 
jython.jar to another location and pointing the classpath to it will 
work in the following cases:

1.
jython.jar is a standalone jar (which contains the /Lib folder)

2.
jython knows the path to the /Lib folder (using -Dpython.path in the 
example)
msg4548 (view) Author: (doublep) Date: 2009-04-20.11:20:35
Thank you, I was trying to create a small example (I have a failure in a
huge webap), but couldn't reproduce it.
msg4549 (view) Author: Oti Humbel (otmarhumbel) Date: 2009-04-20.11:22:06
To summarize:

When using jython.jar not containing the /Lib folder, the path to /Lib 
has to be specified.

(Special case: if the classpath points to an installed jython.jar, 
jython guesses the correct path)
msg4550 (view) Author: (doublep) Date: 2009-04-20.11:22:43
However, in my webapp, I can import normal library modules, e.g. 'import
time' succeeds and works fine after that.  I'm confused about what
'python.path' is actually for...
msg4551 (view) Author: Oti Humbel (otmarhumbel) Date: 2009-04-20.11:33:32
I was only guessing what your problem with __future__ was, and tried to 
build a small example.
Web applications might be different, though.

Are you sure you really can import a module living in a .py file ?
(there is no physical time.py file, jython -v and 'import time' gives:
import: 'time' as org.python.modules.time.Time in builtin modules)
msg4552 (view) Author: (doublep) Date: 2009-04-20.11:49:40
Oh, indeed.  I mostly use Java classes and just a few Python library
modules.  When I try to import a non-builtin module I indeed get the
same ImportError, so yes, Jython is not configured properly...

I guess it's not a bug then?
msg4553 (view) Author: Oti Humbel (otmarhumbel) Date: 2009-04-20.11:55:57
doublep - thanks for your feedback!
Now closing as 'works for me'.
msg4554 (view) Author: (doublep) Date: 2009-04-20.12:46:14
One small improvement would be to give a more understandable error
message in such cases.  But anyway, works here now.  Thanks!
History
Date User Action Args
2009-04-20 12:46:14doublepsetmessages: + msg4554
2009-04-20 11:55:57otmarhumbelsetstatus: open -> closed
resolution: works for me
messages: + msg4553
2009-04-20 11:49:40doublepsetmessages: + msg4552
2009-04-20 11:33:33otmarhumbelsetmessages: + msg4551
2009-04-20 11:22:44doublepsetmessages: + msg4550
2009-04-20 11:22:06otmarhumbelsetmessages: + msg4549
2009-04-20 11:20:35doublepsetmessages: + msg4548
2009-04-20 11:15:37otmarhumbelsetfiles: + LibImportTest.sh
messages: + msg4547
2009-04-20 11:09:50otmarhumbelsetfiles: + test_lib_import.py
nosy: + otmarhumbel
messages: + msg4546
2009-04-20 11:08:54otmarhumbelsetfiles: + LibImportTest.java
2009-04-16 13:25:45doublepcreate