wrong ImportError message printed by python3.3 when it can't finda module?

Discussion in 'Python' started by Irmen de Jong, Dec 7, 2012.

  1. Hi,

    I'm seeing that Python 3.3.0 is not printing the correct ImportError when it can't
    import a module that is imported from another module. Instead of printing the name of
    the module it can't import, it prints the name of the module that is doing the faulty
    import.

    Behold:
    I have created:
    importfail\
    __init__.py
    main.py
    sub.py


    [L:\]type importfail\main.py
    from . import sub

    [L:\]type importfail\sub.py
    import nonexisting_module

    [L:\]


    [L:\]c:\Python33\python.exe -m importfail.main
    Traceback (most recent call last):
    File "C:\Python33\lib\runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
    File "C:\Python33\lib\runpy.py", line 73, in _run_code
    exec(code, run_globals)
    File ".\importfail\main.py", line 1, in <module>
    from . import sub
    ImportError: cannot import name sub # <--- huh ?


    Python 3.2 and earlier do the right thing:

    [L:\]c:\Python32\python.exe -m importfail.main
    Traceback (most recent call last):
    File "C:\Python32\lib\runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
    File "C:\Python32\lib\runpy.py", line 73, in _run_code
    exec(code, run_globals)
    File "L:\importfail\main.py", line 1, in <module>
    from . import sub
    File "importfail\sub.py", line 1, in <module>
    import nonexisting_module
    ImportError: No module named nonexisting_module # <--- ok.

    (this is on windows, but on osx I see the same behavior).


    Is there a problem with the rewritten import logic in Python 3.3?

    Thanks
    Irmen de Jong
    Irmen de Jong, Dec 7, 2012
    #1
    1. Advertising

  2. Irmen de Jong

    Peter Otten Guest

    Irmen de Jong wrote:

    > I'm seeing that Python 3.3.0 is not printing the correct ImportError when
    > it can't import a module that is imported from another module. Instead of
    > printing the name of the module it can't import, it prints the name of the
    > module that is doing the faulty import.
    >
    > Behold:
    > I have created:
    > importfail\
    > __init__.py
    > main.py
    > sub.py
    >
    >
    > [L:\]type importfail\main.py
    > from . import sub
    >
    > [L:\]type importfail\sub.py
    > import nonexisting_module
    >
    > [L:\]
    >
    >
    > [L:\]c:\Python33\python.exe -m importfail.main
    > Traceback (most recent call last):
    > File "C:\Python33\lib\runpy.py", line 160, in _run_module_as_main
    > "__main__", fname, loader, pkg_name)
    > File "C:\Python33\lib\runpy.py", line 73, in _run_code
    > exec(code, run_globals)
    > File ".\importfail\main.py", line 1, in <module>
    > from . import sub
    > ImportError: cannot import name sub # <--- huh ?
    >
    >
    > Python 3.2 and earlier do the right thing:
    >
    > [L:\]c:\Python32\python.exe -m importfail.main
    > Traceback (most recent call last):
    > File "C:\Python32\lib\runpy.py", line 160, in _run_module_as_main
    > "__main__", fname, loader, pkg_name)
    > File "C:\Python32\lib\runpy.py", line 73, in _run_code
    > exec(code, run_globals)
    > File "L:\importfail\main.py", line 1, in <module>
    > from . import sub
    > File "importfail\sub.py", line 1, in <module>
    > import nonexisting_module
    > ImportError: No module named nonexisting_module # <--- ok.
    >
    > (this is on windows, but on osx I see the same behavior).


    A paragon of clarity -- ye lurkers, this is how a bug report should be.

    > Is there a problem with the rewritten import logic in Python 3.3?
    >
    > Thanks
    > Irmen de Jong


    I believe this is fixed, see http://bugs.python.org/issue15111
    Peter Otten, Dec 7, 2012
    #2
    1. Advertising

  3. Re: wrong ImportError message printed by python3.3 when it can'tfind a module?

    On 7-12-2012 22:20, Peter Otten wrote:

    > A paragon of clarity -- ye lurkers, this is how a bug report should be.


    :)

    >
    >> Is there a problem with the rewritten import logic in Python 3.3?
    >>
    >> Thanks
    >> Irmen de Jong

    >
    > I believe this is fixed, see http://bugs.python.org/issue15111


    Argh, why didn't I search the bug tracker first: I would have found that one for sure.
    Anyway, thanks for pointing it out.

    The bug is confusing but it doesn't break anything so far. I guess I'll be fine waiting
    for 3.3.1.


    Irmen
    Irmen de Jong, Dec 7, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VYAS ASHISH M-NTB837
    Replies:
    0
    Views:
    387
    VYAS ASHISH M-NTB837
    Jan 7, 2010
  2. Jason Friedman
    Replies:
    0
    Views:
    134
    Jason Friedman
    Dec 27, 2012
  3. Laszlo Nagy
    Replies:
    0
    Views:
    79
    Laszlo Nagy
    Nov 16, 2013
  4. MRAB
    Replies:
    0
    Views:
    95
  5. Laszlo Nagy
    Replies:
    0
    Views:
    75
    Laszlo Nagy
    Nov 16, 2013
Loading...

Share This Page