Repository navigation
Closed
Labels
Description
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?
Reacted by Jonas Trappenberg
Activity
chebee7i commentedon Oct 3, 2016
Googling revealed: enthought/distarray#541 which has the same problem.
chebee7i commentedon Oct 3, 2016
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.
Carreau commentedon Oct 4, 2016
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.chebee7i commentedon Oct 5, 2016
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:
Here is another example:
Carreau commentedon Oct 7, 2016
Can you check what this does , it might help you find the modules that have issues:
lanery commentedon Oct 5, 2017
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):
Then run script1.py in ipython and at the next prompt run anything that throws an exception.
Carreau commentedon Oct 5, 2017
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:
lanery commentedon Oct 5, 2017
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.
Carreau commentedon Oct 5, 2017
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.
alok commentedon Jan 11, 2018
FWIW, I'm getting this error too. No idea why yet.
alanhdu commentedon Jan 22, 2018
So I believe have a reproducible example (using Ubuntu 16.04, Python 3.6, and IPython 6.2.1). If I create a
test.pywith justin it, I can reproduce the noisy traceback with:
Weirdly enough, if you raise another error then this
AttributeErrordisappears and everything works normally.Via
pdb, it seems like the problem is thatmodule(in https://github.com/python/cpython/blob/9089a265918754d95e105a7c4c409ac9352c87bb/Lib/inspect.py#L742-L743) is: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
execso it might take a while.alanhdu commentedon Jan 22, 2018
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: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__.takluyver commentedon Jan 27, 2018
From the traceback, it looks like it might even be an issue with Python's own
inspectlibrary, 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.Antoinelypro commentedon Oct 3, 2018
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
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
olaurino commentedon Oct 26, 2018
I can reproduce a very similar issue (can't be sure it's the same) pretty easily in ipython 6.5 and 7:
Note that I can't reproduce it in Python:
The only workaround I could find was to set
sys.tracebacklimit=None:olaurino commentedon Oct 26, 2018
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.tracebacklimitis set to a value.patnr commentedon Sep 25, 2019
As Alanhdu said, the issue arises if one does
%runa file that importsmultiprocessing(orscipy.stats, etc...), which setssys.modules['__mp_main__']tosys.modules['__main__'].I'm not sure, but it seems to me that the
finallyclause in%runshould restore not just
__main__but also__mp_main__,for example as such:
OceanNuclear commentedon Nov 22, 2019
@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.
Carreau commentedon Nov 22, 2019
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.
Fix the issue with %run-ing something with multiprocessing
Carreau commentedon Nov 22, 2019
Can you try #11959 ?
OceanNuclear commentedon Nov 22, 2019
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, minimizeI was able to replicate the issue within the conda environment "canary":(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:
Should I keep these changes locally or should I wait for an updated version of ipython to be released, and do
conda update IPython?Carreau commentedon Nov 24, 2019
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.