[Tutor] Can not run under python 2.6?

Kent Johnson kent37 at tds.net
Wed Apr 29 13:02:22 CEST 2009


On Wed, Apr 29, 2009 at 2:19 AM, Jianchun Zhou <jianchun.zhou at gmail.com> wrote:
> Hi, there:
>
> I am new to python, and now I got a trouble:
>
> I have an application named canola, it is written under python 2.5, and can
> run normally under python 2.5
>
> But when it comes under python 2.6, problem up, it says:
>
> Traceback (most recent call last):
>   File "/usr/lib/python2.6/site-
> packages/terra/core/plugin_manager.py", line 151, in _load_plugins
>     classes = plg.load()
>   File "/usr/lib/python2.6/site-packages/terra/core/plugin_manager.py", line
> 94, in load
>     mod = self._ldr.load()
>   File "/usr/lib/python2.6/site-packages/terra/core/module_loader.py", line
> 42, in load
>     mod = __import__(modpath, fromlist=[mod_name])
> ImportError: Import by filename is not supported.
>
> Any body any idea what should I do?

What's New in Python 2.6 says, "Due to an implementation accident, if
you passed a file path to the built-in __import__() function, it would
actually import the specified file. This was never intended to work,
however, and the implementation now explicitly checks for this case
and raises an ImportError."

It looks like imp.load_source() may do what you want.

Kent


More information about the Tutor mailing list