Mailing List Archive

Running idle as a package
I was trying to run idle as a package, so I turned the idle
directory into a python package. But then I got:

Python 1.5.2 (#2, Apr 21 1999, 17:14:19) [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from idle import idle
Failed to load extension 'SearchBinding'
Traceback (innermost last):
File "/usr/local/lib/python1.5/site-packages/idle/EditorWindow.py", line 470, in
load_standard_extensions
self.load_extension(name)
File "/usr/local/lib/python1.5/site-packages/idle/EditorWindow.py", line 481, in load_extension
mod = __import__(name)
ImportError: No module named SearchBinding
...

Apparently the problem is caused by the call to __import__,
that is not aware of the intra-package shortcut.

I have been able to solve this for my case as follows:

diff -r1.1 EditorWindow.py
481c481,482
< mod = __import__(name)
---
> pck = __import__('idle.' + name)
> mod = getattr(pck, name)

Regards, Jan

--
===================================================================
Jan Decaluwe === Easics ===
Design Manager === VHDL-based ASIC design services ===
Tel: +32-16-395 600 ===================================
Fax: +32-16-395 619 Interleuvenlaan 86, B-3001 Leuven, BELGIUM
mailto:jand@easics.be http://www.easics.com
Running idle as a package [ In reply to ]
Jan Decaluwe <jand@easics.be> writes:

> I was trying to run idle as a package, so I turned the idle
> directory into a python package. But then I got:
>
> Python 1.5.2 (#2, Apr 21 1999, 17:14:19) [GCC 2.8.1] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> from idle import idle
> Failed to load extension 'SearchBinding'
> Traceback (innermost last):
> File "/usr/local/lib/python1.5/site-packages/idle/EditorWindow.py", line 470, in
> load_standard_extensions
> self.load_extension(name)
> File "/usr/local/lib/python1.5/site-packages/idle/EditorWindow.py", line 481, in load_extension
> mod = __import__(name)
> ImportError: No module named SearchBinding
> ...
>
> Apparently the problem is caused by the call to __import__,
> that is not aware of the intra-package shortcut.

Thanks. A better fix (that works whether or not idle is being used as
a package) is to change the __import__ call as follows (line numbers
may be off):

*** EditorWindow.py 1999/04/20 15:45:28 1.18
--- EditorWindow.py 1999/04/23 13:42:38
***************
*** 484,490 ****
return extend.standard

def load_extension(self, name):
! mod = __import__(name)
cls = getattr(mod, name)
ins = cls(self)
self.extensions[name] = ins
--- 484,490 ----
return extend.standard

def load_extension(self, name):
! mod = __import__(name, globals(), locals(), [])
cls = getattr(mod, name)
ins = cls(self)
self.extensions[name] = ins

--Guido van Rossum (home page: http://www.python.org/~guido/)