Skip to content

Noisy tracebacks? #9978

Closed
Closed

Description

@chebee7i

There has been a change in how tracebacks are shown when running scripts. Example:

Traceback (most recent call last):
  File "/path/to/my/venv/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-fdeb52d5be8d>", line 1, in <module>
    f.something()
  File "/path/to/some/file.py", line 68, in something
    assert 1 is not None
AssertionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/path/to/my/venv/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 1821, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'AssertionError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/path/to/my/venv/lib/python3.5/site-packages/IPython/core/ultratb.py", line 1132, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "/path/to/my/venv/lib/python3.5/site-packages/IPython/core/ultratb.py", line 313, in wrapped
    return f(*args, **kwargs)
  File "/path/to/my/venv/lib/python3.5/site-packages/IPython/core/ultratb.py", line 358, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/path/to/my/venv/lib/python3.5/inspect.py", line 1455, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "/path/to/my/venv/lib/python3.5/inspect.py", line 1412, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/path/to/my/venv/lib/python3.5/inspect.py", line 672, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "/path/to/my/venv/lib/python3.5/inspect.py", line 720, in getmodule
    os.path.realpath(f)] = module.__name__
AttributeError: module has no attribute '__name__'

This is quite noisy especially since the later two exceptions have nothing to do with my script. Can IPython do something to quiet this down? To be clear, AssertionError is not the problem. If I replace line 68 with 1/0, then you get `AttributeError: 'ZeroDivisionError' object has no attribute 'render_traceback'. So it seems like IPython is making some assumptions that no longer hold in Python 3?

Activity

  1. chebee7i commented on Oct 3, 2016

    @chebee7i
    ContributorAuthor

    Googling revealed: enthought/distarray#541 which has the same problem.

  2. chebee7i commented on Oct 3, 2016

    @chebee7i
    ContributorAuthor

    It looks like this may have been discussed on the Python mailing list too: https://mail.python.org/pipermail/python-list/2015-February/685695.html

    They concluded it was a versioning issue, but I'm IPython 5.1.0 and I still have the issue.

  3. Carreau commented on Oct 4, 2016

    @Carreau
    Member

    Can yo provide your file.py, I can't seem toreproduce your behavior.

    The later 2 exceptions are a Python 3 think IIUC, but they should be caught and silence by IPython though.

    I'm curious as to what kind of module might not have a __name__ because just silencing such an error seem like a bad idea.

  4. chebee7i commented on Oct 5, 2016

    @chebee7i
    ContributorAuthor

    Hmm, it seems to be a bit trickier to recreate the issue in minimal code. I am going to have to get back to you. I can reproduce the bug at will in a larger non-minimal example, but just when I thought I had isolated the root cause and tried to produce the minimal example, I couldn't reproduce it. So it is only reproducible in my environment right now.

    Here's what I know:

    • The contents of file.py don't matter per se. All that matters is that you import some package that was "pip install -e" and have the script raise some exception. Then, you can do any new exception in IPython after the fact.
    • However, it doesn't appear to be any "pip install -e"'d package will do the job...this is where I got stuck making a minimal example.

    Here is another example:

    $ ipython
    Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06)
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.1.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: run demo.py
    ---------------------------------------------------------------------------
    ZeroDivisionError                         Traceback (most recent call last)
    /path/to/script/demo.py in <module>()
          1 import pip_installed_dash_e_package
    ----> 2 1/0
    
    ZeroDivisionError: division by zero
    
    In [2]: a
    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.
    
    Traceback (most recent call last):
      File "/path/to/virtualenv/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2883, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-2-60b725f10c9c>", line 1, in <module>
        a
    NameError: name 'a' is not defined
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/path/to/virtualenv/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 1823, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'NameError' object has no attribute '_render_traceback_'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/path/to/virtualenv/lib/python3.5/site-packages/IPython/core/ultratb.py", line 1132, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "/path/to/virtualenv/lib/python3.5/site-packages/IPython/core/ultratb.py", line 313, in wrapped
        return f(*args, **kwargs)
      File "/path/to/virtualenv/lib/python3.5/site-packages/IPython/core/ultratb.py", line 358, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "/path/to/virtualenv/lib/python3.5/inspect.py", line 1453, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "/path/to/virtualenv/python3.5/inspect.py", line 1410, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/path/to/virtualenv/python3.5/inspect.py", line 672, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/path/to/virtualenv/python3.5/inspect.py", line 718, in getmodule
        os.path.realpath(f)] = module.__name__
    AttributeError: module has no attribute '__name__'
    ---------------------------------------------------------------------------
    
  5. Carreau commented on Oct 7, 2016

    @Carreau
    Member

    Can you check what this does , it might help you find the modules that have issues:

    In [2]: import sys, types
    
    In [3]: { k:type(v) for k,v in sys.modules.items() if type(v) is not types.ModuleType}
    Out[3]:
    {'pkg_resources._vendor.six.moves': pkg_resources._vendor.six._MovedItems,
     'pkg_resources.extern.six.moves': pkg_resources._vendor.six._MovedItems,
     'pkg_resources.extern.six.moves.urllib': pkg_resources._vendor.six.Module_six_moves_urllib,
     'pygments.formatters': pygments.formatters._automodule,
     'pygments.lexers': pygments.lexers._automodule,
     'six.moves': six._MovedItems,
     'six.moves.urllib': six.Module_six_moves_urllib,
     'six.moves.urllib.parse': six.Module_six_moves_urllib_parse,
     'sphinx.util.pycompat': sphinx.util.pycompat._DeprecationWrapper}
    
  6. lanery commented on Oct 5, 2017

    @lanery

    I am also experiencing this crazy traceback after trying multiple versions of IPython as well as uninstalling my Anaconda distribution and installing miniconda.
    Now running python 3.6.2 and IPython 6.1.0.

    I found a culprit package: skimage.external.tifffile.
    My attempt at a MCVE (sorry if this doesn't help any more than @chebee7i's description):

    # simple directory tree
    *
    + -- script1.py
    + -- script2.py
    
    # script2.py
    from skimage.external import tifffile
    
    def func():
        raise ValueError()
    
    # script1.py
    from script2 import func
    func()
    

    Then run script1.py in ipython and at the next prompt run anything that throws an exception.

    H:\projects\SECOM\test_images_sb
    λ  ipython
    Python 3.6.2 |Anaconda, Inc.| (default, Sep 19 2017, 08:03:39) [MSC v.1900 64 bit (AMD64)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: run script1
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    H:\projects\SECOM\test_images_sb\script1.py in <module>()
          9 from script2 import func
         10
    ---> 11 func()
    
    H:\projects\SECOM\test_images_sb\script2.py in func()
         10
         11 def func():
    ---> 12     raise ValueError()
    
    ValueError:
    
    In [2]: undefined_variable
    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.
    
    Traceback (most recent call last):
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-2-323f7d73223b>", line 1, in <module>
        undefined_variable
    NameError: name 'undefined_variable' is not defined
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 1806, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'NameError' object has no attribute '_render_traceback_'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\ultratb.py", line 1090, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\ultratb.py", line 311, in wrapped
        return f(*args, **kwargs)
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\site-packages\IPython\core\ultratb.py", line 345, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\inspect.py", line 1480, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\inspect.py", line 1438, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\inspect.py", line 693, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "C:\Users\rlane\AppData\Local\Continuum\miniconda3\lib\inspect.py", line 739, in getmodule
        os.path.realpath(f)] = module.__name__
    AttributeError: module has no attribute '__name__'
    ---------------------------------------------------------------------------
    
  7. Carreau commented on Oct 5, 2017

    @Carreau
    Member

    Thanks @lanery ; having a minimal reproducible version would be helpful; I used what you said, but cant' reproduce here. Which versions of Python are you using ?

    In fresh conda-env, with IPython and skimage I cant' reproduce:

    Session:
    bash-3.2$ ipython
    Python 3.6.2 | packaged by conda-forge | (default, Jul 23 2017, 23:01:38)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: import IPython
    
    In [2]: IPython.__file__
    Out[2]: '/Users/bussonniermatthias/anaconda/lib/python3.6/site-packages/IPython/__init__.py'
    
    In [3]: run s1.py
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    ~/eraseme/s1.py in <module>()
          1 from s2 import func
    ----> 2 func()
    
    ~/eraseme/s2.py in func()
          2
          3 def func():
    ----> 4     raise ValueError()
    
    ValueError:
    
    In [4]: b
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    <ipython-input-4-89e6c98d9288> in <module>()
    ----> 1 b
    
    NameError: name 'b' is not defined
    
    In [5]: !cat s1.py
    from s2 import func
    func()
    
    In [6]: ! cat s2.py
    from skimage.external import tifffile
    
    def func():
        raise ValueError()
    
  8. lanery commented on Oct 5, 2017

    @lanery

    I also was not able to reproduce the error when I tried on my home system (Mac OSX running python 3.5.2, IPython 5.1.0, skimage 0.13.0). The system that was failing was running Windows with python 3.6, IPython 5.1.0 and 6.2, skimage 0.13.1 and 0.14.1. I tried multiple versions for IPython and skimage to no avail.

  9. Carreau commented on Oct 5, 2017

    @Carreau
    Member

    Hum, that is strange; there is probably something going on with some hidden state and/or caching.
    I'll see if I can try to add some check to get better informations on what is happening.

  10. alok commented on Jan 11, 2018

    @alok
    Contributor

    FWIW, I'm getting this error too. No idea why yet.

  11. alanhdu commented on Jan 22, 2018

    @alanhdu

    So I believe have a reproducible example (using Ubuntu 16.04, Python 3.6, and IPython 6.2.1). If I create a test.py with just

    import multiprocessing as mp

    in it, I can reproduce the noisy traceback with:

    In [1]: %run test.py
    
    In [2]: a
    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.
    
    Traceback (most recent call last):
      File "/home/alan/workspace/ctrl-labs/py3.venv/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-2-3f786850e387>", line 1, in <module>
        a
    NameError: name 'a' is not defined
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/alan/workspace/ctrl-labs/py3.venv/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 1828, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'NameError' object has no attribute '_render_traceback_'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/alan/workspace/ctrl-labs/py3.venv/lib/python3.6/site-packages/IPython/core/ultratb.py", line 1090, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "/home/alan/workspace/ctrl-labs/py3.venv/lib/python3.6/site-packages/IPython/core/ultratb.py", line 311, in wrapped
        return f(*args, **kwargs)
      File "/home/alan/workspace/ctrl-labs/py3.venv/lib/python3.6/site-packages/IPython/core/ultratb.py", line 345, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "/opt/anaconda/lib/python3.6/inspect.py", line 1483, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "/opt/anaconda/lib/python3.6/inspect.py", line 1441, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/opt/anaconda/lib/python3.6/inspect.py", line 696, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/opt/anaconda/lib/python3.6/inspect.py", line 742, in getmodule
        os.path.realpath(f)] = module.__name__
    AttributeError: module has no attribute '__name__'
    ---------------------------------------------------------------------------

    Weirdly enough, if you raise another error then this AttributeError disappears and everything works normally.

    Via pdb, it seems like the problem is that module (in https://github.com/python/cpython/blob/9089a265918754d95e105a7c4c409ac9352c87bb/Lib/inspect.py#L742-L743) is:

    <module '?' from '/home/alan/workspace/scratch/test.py'>

    and indeed it has no __name__ attribute attached to it.

    I'm trying to figure out a fix, but I'm not very familiar enough the Python internals or exec so it might take a while.

  12. alanhdu commented on Jan 22, 2018

    @alanhdu

    So it appears to be an interaction between multiprocessing and https://github.com/ipython/ipython/blob/master/IPython/core/magics/execution.py#L785 -- with the pop, I get:

    In [1]: %run test.py
    
    In [2]:  import sys; [(key, module) for key, module in sys.modules.items() if not hasattr(module, "__name__")]
    Out[2]: [('__mp_main__', <module '?' from '/home/alan/workspace/scratch/test.py'>)]

    without it, I get an empty list.

    Is the solution to also try sys.modules.pop("__mp_main__", None) here (or maybe snapshotting it at the beginning and restoring it)? I don't really know too much about __mp_main__.

  13. takluyver commented on Jan 27, 2018

    @takluyver
    Member

    From the traceback, it looks like it might even be an issue with Python's own inspect library, which assumes that modules have a __name__ attribute. We do already go to some lengths to work around inspect issues, but I'd rather not pile on more monkeypatches.

  14. Antoinelypro commented on Oct 3, 2018

    @Antoinelypro

    Hi,

    I am still having the issue. I have so fare update libraries. Below are details.

    [EDIT] : updating python version as well as ipykernel fixed it. The issue occured only with ipython but not python.

    code
    from sklearn.preprocessing import OrdinalEncoder
    enc = OrdinalEncoder()

    stdout

    Traceback (most recent call last):
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-0a61fe33cb2a>", line 1, in <module>
        from sklearn.preprocessing import OrdinalEncoder
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py", line 6, in <module>
        from ._function_transformer import FunctionTransformer
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\sklearn\preprocessing\_function_transformer.py", line 5, in <module>
        from ..utils.testing import assert_allclose_dense_sparse
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\sklearn\utils\testing.py", line 758, in <module>
        import pytest
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\pytest.py", line 9, in <module>
        from _pytest.config import main, UsageError, cmdline, hookspec, hookimpl
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 19, in <module>
        import _pytest.hookspec  # the extension point definitions
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\_pytest\hookspec.py", line 27, in <module>
        @hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
    TypeError: __call__() got an unexpected keyword argument 'warn_on_impl'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 1821, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'TypeError' object has no attribute '_render_traceback_'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1132, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 313, in wrapped
        return f(*args, **kwargs)
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 358, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "C:\Users\antoine.ly\Anaconda3\lib\inspect.py", line 1459, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "C:\Users\antoine.ly\Anaconda3\lib\inspect.py", line 1417, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "C:\Users\antoine.ly\Anaconda3\lib\inspect.py", line 677, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "C:\Users\antoine.ly\Anaconda3\lib\inspect.py", line 714, in getmodule
        if ismodule(module) and hasattr(module, '__file__'):
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\py\_vendored_packages\apipkg.py", line 195, in __getattribute__
        return getattr(getmod(), name)
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\py\_vendored_packages\apipkg.py", line 179, in getmod
        x = importobj(modpath, None)
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\py\_vendored_packages\apipkg.py", line 69, in importobj
        module = __import__(modpath, None, None, ['__doc__'])
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\pytest.py", line 9, in <module>
        from _pytest.config import main, UsageError, cmdline, hookspec, hookimpl
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 19, in <module>
        import _pytest.hookspec  # the extension point definitions
      File "C:\Users\antoine.ly\Anaconda3\lib\site-packages\_pytest\hookspec.py", line 27, in <module>
        @hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
    TypeError: __call__() got an unexpected keyword argument 'warn_on_impl'
    

    version
    3.5.6

    requirements
    alabaster==0.7.11
    art==2.3
    atomicwrites==1.2.1
    attrs==18.2.0
    awscli==1.14.25
    Babel==2.6.0
    backcall==0.1.0
    certifi==2018.8.24
    chardet==3.0.4
    codecov==2.0.15
    colorama==0.3.9
    coverage==4.5.1
    cycler==0.10.0
    decorator==4.3.0
    docutils==0.14
    et-xmlfile==1.0.1
    idna==2.7
    imagesize==1.1.0
    ipykernel==5.0.0
    ipython==7.0.1
    ipython-genutils==0.2.0
    jdcal==1.4
    jedi==0.13.1
    Jinja2==2.10
    jmespath==0.9.3
    jupyter-client==5.2.3
    jupyter-core==4.4.0
    kiwisolver==1.0.1
    MarkupSafe==1.0
    matplotlib==3.0.0
    more-itertools==4.3.0
    numpy==1.15.2
    openpyxl==2.5.8
    packaging==18.0
    pandas==0.23.4
    parso==0.3.1
    pathlib2==2.3.2
    pickleshare==0.7.5
    pluggy==0.7.1
    prompt-toolkit==2.0.5
    py==1.6.0
    pyasn1==0.4.2
    pycm==1.2
    Pygments==2.2.0
    pyparsing==2.2.2
    pytest==3.8.1
    pytest-cov==2.6.0
    python-dateutil==2.6.1
    pytz==2018.5
    pyzmq==17.1.2
    requests==2.19.1
    rsa==3.4.2
    s3transfer==0.1.12
    scikit-learn==0.20.0
    scipy==1.1.0
    seaborn==0.9.0
    simplegeneric==0.8.1
    six==1.11.0
    snowballstemmer==1.2.1
    Sphinx==1.8.1
    sphinxcontrib-websupport==1.1.0
    tornado==5.1.1
    traitlets==4.3.2
    urllib3==1.23
    wcwidth==0.1.7
    win-unicode-console==0.5
    wincertstore==0.2

  15. olaurino commented on Oct 26, 2018

    @olaurino

    I can reproduce a very similar issue (can't be sure it's the same) pretty easily in ipython 6.5 and 7:

    ipython -c "import sys; sys.tracebacklimit=0; a"
    

    Note that I can't reproduce it in Python:

    python -c "import sys; sys.tracebacklimit=0; a" 
    NameError: name 'a' is not defined
    

    The only workaround I could find was to set sys.tracebacklimit=None:

    ipython -c "import sys; sys.tracebacklimit=None; a"
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    <ipython-input-1-05b18c546f64> in <module>
    ----> 1 import sys; sys.tracebacklimit=None; a
    
    NameError: name 'a' is not defined
    
  16. olaurino commented on Oct 26, 2018

    @olaurino

    I can also do something a little more complicated, which shows that the problem is not just the value 0, but there may be something wrong with the way ipython interacts with python when sys.tracebacklimit is set to a value.

    Python 3.7.1 (default, Oct 23 2018, 19:19:42)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: def foo():
       ...:     def bar():
       ...:         1/0
       ...:     bar()
       ...: 
    
    In [2]: foo()
    ---------------------------------------------------------------------------
    ZeroDivisionError                         Traceback (most recent call last)
    <ipython-input-2-c19b6d9633cf> in <module>()
    ----> 1 foo()
    
    <ipython-input-1-f22da8730e15> in foo()
          2     def bar():
          3         1/0
    ----> 4     bar()
          5
    
    <ipython-input-1-f22da8730e15> in bar()
          1 def foo():
          2     def bar():
    ----> 3         1/0
          4     bar()
          5
    
    ZeroDivisionError: division by zero
    
    In [3]: import sys
    
    In [4]: sys.tracebacklimit=2
    
    In [5]: foo()
    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.
    
    Traceback (most recent call last):
      File "/export/miniconda/miniconda/envs/test-ipython/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-5-c19b6d9633cf>", line 1, in <module>
        foo()
    ZeroDivisionError: division by zero
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/export/miniconda/miniconda/envs/test-ipython/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 1863, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'ZeroDivisionError' object has no attribute '_render_traceback_'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/export/miniconda/miniconda/envs/test-ipython/lib/python3.7/site-packages/IPython/core/ultratb.py", line 1095, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "/export/miniconda/miniconda/envs/test-ipython/lib/python3.7/site-packages/IPython/core/ultratb.py", line 311, in wrapped
        return f(*args, **kwargs)
    AssertionError
    ---------------------------------------------------------------------------
    
  17. patnr commented on Sep 25, 2019

    @patnr

    As Alanhdu said, the issue arises if one does %run a file that imports multiprocessing (or scipy.stats, etc...), which sets
    sys.modules['__mp_main__'] to sys.modules['__main__'].
    I'm not sure, but it seems to me that the finally clause in %run
    should restore not just __main__ but also __mp_main__,
    for example as such:

                 # Ensure key global structures are restored
                 sys.argv = save_argv
                 if restore_main:
                     sys.modules['__main__'] = restore_main
    +                if '__mp_main__' in sys.modules:
    +                    sys.modules['__mp_main__'] = restore_main
    
  18. OceanNuclear commented on Nov 22, 2019

    @OceanNuclear

    @patricknraanes May I know if you have resolved this issue by editing that particular file? Or did you solve it by adding a new channel to conda/pip? Or updating conda/pip?

    I've had this problem with Python 3.8.0/IPython 7.8.0 for two weeks now, but seeing how dead this thread is I assume I'm the only one having this problem right now.

    After re-installing conda multiple times, this same problem still shows up. But my system version of python (managed by pip of course) which is stuck in version 3.6.8, has no such problem. In fact I've found out that if I downgrade my conda down to 3.6.x, it won't have any of such problem.

  19. Carreau commented on Nov 22, 2019

    @Carreau
    Member

    The patch above seem to fix the issue when run manually; though I cannot seem to reproduce the issue from within the test suite; which would be great to make sure this is actually fixed on all platforms.

  20. added a commit that references this issue on Nov 22, 2019
    1344102
  21. Carreau commented on Nov 22, 2019

    @Carreau
    Member

    Can you try #11959 ?

  22. OceanNuclear commented on Nov 22, 2019

    @OceanNuclear

    YES! Thank you, problem fixed! (Sorry for the long wait)
    Using a testscript.py which only contains one line:from scipy.optimize import fsolve, root, Bounds, minimize I was able to replicate the issue within the conda environment "canary":

    (canary) ~/ ipython
    Python 3.8.0 (default, Nov 6 2019, 21:49:08)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.`

    In [1]: run testscript.py

    In [2]: x
    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.

    Traceback (most recent call last):
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
    File "", line 1, in
    x
    NameError: name 'x' is not defined

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2040, in showtraceback
    stb = value.render_traceback()
    AttributeError: 'NameError' object has no attribute 'render_traceback'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1101, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/site-packages/IPython/core/ultratb.py", line 319, in wrapped
    return f(*args, **kwargs)
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/site-packages/IPython/core/ultratb.py", line 353, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/inspect.py", line 1503, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/inspect.py", line 1461, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/inspect.py", line 708, in getsourcefile
    if getattr(getmodule(object, filename), 'loader', None) is not None:
    File "/home/ocean/miniconda3/envs/canary/lib/python3.8/inspect.py", line 754, in getmodule
    os.path.realpath(f)] = module.name
    AttributeError: module has no attribute 'name'

    (I can confirm that this is exactly the same issue that I've encountered while using python 3.7.x as well)
    and after editing those two files in #11959 the problem went away:

    (canary) ~/ ipython
    Python 3.8.0 (default, Nov 6 2019, 21:49:08)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.

    In [1]: run testscript.py

    In [2]: x

    NameError Traceback (most recent call last)
    in
    ----> 1 x

    NameError: name 'x' is not defined

    Should I keep these changes locally or should I wait for an updated version of ipython to be released, and do conda update IPython?

  23. Carreau commented on Nov 24, 2019

    @Carreau
    Member

    Should I keep these changes locally or should I wait for an updated version of ipython to be released, and do conda update IPython?

    The fix will be included in next release. Usually last friday of the month, but next week is holliday so well likely soon. Once 7.10 is released you'll be able to just update with conda.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions