[IronPython] True division error

Martin Maly Martin.Maly at microsoft.com
Sun Jul 2 19:27:04 CEST 2006

This is actually a correct behavior (*). The "from __future__ import division" is detected at compile-time, which is what will affect the division IronPython uses in the given module. However, the module will still try to import the module called "__future__" at runtime. Since IronPython distribution doesn't contain that module, you'll see the exception you are getting. What you can do is point IronPython to the standard python library directory (for example C:\Python24\Lib) and IronPython will find the __future__.py module which is part of standard Python. The easy way to do this once and for all is to modify IronPython's site.py (the only file in the IronPython's Lib directory):

import sys

(*) you can try similar trick with standard Python. This snippet will clear the import search path so the import statement will not find the module __future__.py, but the division behavior will still get changed.

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path = []
>>> 1/2
>>> from __future__ import division
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named __future__
>>> 1/2

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Kristof Wagemans
Sent: Sunday, July 02, 2006 12:40 AM
To: 'Discussion of IronPython'
Subject: [IronPython] True division error

IronPython 1.0.2365 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> 1/2
>>> from __future__ import division
Traceback (most recent call last):
  File , line 0, in <stdin>##3
  File , line 0, in __import__##7
ImportError: No module named __future__
>>> 1/2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060702/0b73cae0/attachment.html>

More information about the Ironpython-users mailing list