Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'get_current_traceback' from 'werkzeug.debug.tbtools' #1992

Closed
52-41-4d opened this issue Mar 28, 2022 · 19 comments · Fixed by #1995
Closed

Comments

@52-41-4d
Copy link

I am working on a Dash app and it was working great till yesterday. When I tried today, I am seeing the following:

Traceback (most recent call last):
File "/app/app-v2.py", line 12, in
import dash
File "/usr/local/lib/python3.9/site-packages/dash/init.py", line 5, in
from .dash import Dash, no_update # noqa: F401,E402
File "/usr/local/lib/python3.9/site-packages/dash/dash.py", line 18, in
from werkzeug.debug.tbtools import get_current_traceback
ImportError: cannot import name 'get_current_traceback' from 'werkzeug.debug.tbtools' (/usr/local/lib/python3.9/site-packages/werkzeug/debug/tbtools.py)

I am running the app on macOS Catalina. Happy to provide more details.

@52-41-4d
Copy link
Author

Update. I have downgraded the werkzeug version to 2.0.0 and it works. For some reason, 2.1.0 doesn't. FYI. Thanks for your efforts.

@renderbot
Copy link

renderbot commented Mar 28, 2022

Just commenting that I hit the same issue with Werkzeug--pinning 2.0.3 seemed to resolve--Linux Mint 20.3

@DrGFreeman
Copy link

From Werkzeug 2.1.0 release notes (https://werkzeug.palletsprojects.com/en/2.1.x/changes/#version-2-1-0):

Refactor the debugger traceback formatter to use Python’s built-in traceback module as much as possible. #1753

@Bachibouzouk
Copy link

Bachibouzouk commented Mar 28, 2022

It seems that get_current_traceback changed to DebugTraceback

I simply replaced get_current_traceback by DebugTraceback in the dash.py file and it worked

@michelegentili93
Copy link

michelegentili93 commented Mar 28, 2022

I can't downgrade. I have Python 3.8.8

If I run
pip install -i Werkzeug== 2.1.0

I get

Looking in indexes: Werkzeug==
WARNING: Url 'Werkzeug==/2-1-0/' is ignored. It is either a non-existing path or lacks a specific scheme.
ERROR: Could not find a version that satisfies the requirement 2.1.0 (from versions: none)
ERROR: No matching distribution found for 2.1.0

@Bachibouzouk
Copy link

Bachibouzouk commented Mar 28, 2022

@michelegentili93

pip install -i Werkzeug== 2.1.0

you have a space between the == and the version number, this is probably what causes the error
Try pip install -i Werkzeug==2.1.0

@deepyaman
Copy link

It seems that get_current_traceback changed to DebugTraceback

I simply replaced get_current_traceback by DebugTraceback in the dash.py file and it worked

@Bachibouzouk I did this initially in #1993, but that would mean giving up Python 3.6 compatibility. I'm not sure what the Dash view is on this, given it's EOL (I couldn't find any open issues about it on GitHub), but I figured we should just bound the dependencies until there's an explicit agreement to drop 3.6.

@Stayermax
Copy link

pip install -i Werkzeug==2.1.0 didn't work for me, but pip install Werkzeug==2.0.0 did.

@flying-sheep
Copy link

flying-sheep commented Mar 29, 2022

Pinning a dependency’s max version is a good idea in the following situations:

  • a temporary fix for CI since the dependency has a bug (this is what people depending on dash are doing right now)
  • a medium term fix for an end user application (i.e. a project that isn’t imported by any other)

It’s not a good medium or even long term solution for a library like dash. Library projects should have conditional code that copes with both new and old dependency versions if possible, and if not, raise minimum dependency versions (in this case, Python’s)

see here for reasons: https://iscinumpy.dev/post/bound-version-constraints/

@anders-kiaer
Copy link
Contributor

anders-kiaer commented Mar 29, 2022

It seems that get_current_traceback changed to DebugTraceback
I simply replaced get_current_traceback by DebugTraceback in the dash.py file and it worked

@Bachibouzouk I did this initially in #1993, but that would mean giving up Python 3.6 compatibility. I'm not sure what the Dash view is on this, given it's EOL (I couldn't find any open issues about it on GitHub), but I figured we should just bound the dependencies until there's an explicit agreement to drop 3.6.

@deepyaman Thanks for attempting a PR fix on this. I haven't looked at the details yet (except pinning version in our CI), but if it is only the name that has changed of what is imported, would something like the common import catching pattern

try:
   from werkzeug.debug.tbtools import DebugTraceback
except ImportError:  # temporary fallback for werkzeug<2.1
   from werkzeug.debug.tbtools import get_current_traceback as DebugTraceback

(together with replacing get_current_traceback with DebugTraceback where it is used) work also here?

@Bachibouzouk
Copy link

Bachibouzouk commented Mar 29, 2022

(together with replacing get_current_traceback with DebugTraceback where it is used) work also here?

@anders-kiaer - this work to get rid of the error, I am not sure it keeps the desired functionality (The DebugTraceback class seem to take an exception as argument upon initialisation looking at the PR which did the change pallets/werkzeug#2333)

@deepyaman
Copy link

It seems that get_current_traceback changed to DebugTraceback
I simply replaced get_current_traceback by DebugTraceback in the dash.py file and it worked

@Bachibouzouk I did this initially in #1993, but that would mean giving up Python 3.6 compatibility. I'm not sure what the Dash view is on this, given it's EOL (I couldn't find any open issues about it on GitHub), but I figured we should just bound the dependencies until there's an explicit agreement to drop 3.6.

@deepyaman Thanks for attempting a PR fix on this. I haven't looked at the details yet (except pinning version in our CI), but if it is only the name that has changed of what is imported, would something like the common import catching pattern

try:
   from werkzeug.debug.tbtools import DebugTraceback
except ImportError:  # temporary fallback for werkzeug<2.1
   from werkzeug.debug.tbtools import get_current_traceback as DebugTraceback

(together with replacing get_current_traceback with DebugTraceback where it is used) work also here?

@anders-kiaer I think it would work with a bit more effort. DebugTraceback takes the exception as an argument. However, what we can do is to just implement DebugTraceback for werkzeug<2.1 as:

def DebugTraceback(e: Exception):
    return get_current_traceback()

or something like that (very rough here).

@fdosani
Copy link

fdosani commented Mar 29, 2022

Pinning a dependency’s max version is a good idea in the following situations:

  • a temporary fix for CI since the dependency has a bug (this is what people depending on dash are doing right now)
  • a medium term fix for an end user application (i.e. a project that isn’t imported by any other)

It’s not a good medium or even long term solution for a library like dash. Library projects should have conditional code that copes with both new and old dependency versions if possible, and if not, raise minimum dependency versions (in this case, Python’s)

see here for reasons: https://iscinumpy.dev/post/bound-version-constraints/

Interesting article, thanks for sharing. Just for context, I was alerted this this issues due to a tool we've been working on called edgetest. It helps automate the upper pins and is in the same realm of GitHub's dependabot. Full disclosure I'm one of the devs who works on this package. Just sharing incase this could be useful to anyone.

At a minimum it will test the latest versions and bump them up only if your CICD testing passes. There is also an action to help automate some of this.

@deepyaman
Copy link

It seems that get_current_traceback changed to DebugTraceback
I simply replaced get_current_traceback by DebugTraceback in the dash.py file and it worked

@Bachibouzouk I did this initially in #1993, but that would mean giving up Python 3.6 compatibility. I'm not sure what the Dash view is on this, given it's EOL (I couldn't find any open issues about it on GitHub), but I figured we should just bound the dependencies until there's an explicit agreement to drop 3.6.

@deepyaman Thanks for attempting a PR fix on this. I haven't looked at the details yet (except pinning version in our CI), but if it is only the name that has changed of what is imported, would something like the common import catching pattern

try:
   from werkzeug.debug.tbtools import DebugTraceback
except ImportError:  # temporary fallback for werkzeug<2.1
   from werkzeug.debug.tbtools import get_current_traceback as DebugTraceback

(together with replacing get_current_traceback with DebugTraceback where it is used) work also here?

@anders-kiaer I think it would work with a bit more effort. DebugTraceback takes the exception as an argument. However, what we can do is to just implement DebugTraceback for werkzeug<2.1 as:

def DebugTraceback(e: Exception):
    return get_current_traceback()

or something like that (very rough here).

Actually, there's some other work that would need to be done. Working on an implementation, but here's another change from:

https://github.com/pallets/werkzeug/blob/a04f5cc32be020babeaf9474f7ac735422ddc824/src/werkzeug/debug/__init__.py#L329-L331

to:

https://github.com/pallets/werkzeug/blob/560dd5f320bff318175f209595d42f5a80045417/src/werkzeug/debug/__init__.py#L325-L329

But I can account for this.

@yash-pandey24
Copy link

You are life saver bro. Thanks a lot:)

@deepyaman
Copy link

I tried to implement the suggestions in #1993, but I see that @T4rk1n opened #1995 that also addresses the same (albeit slightly differently). Happy to close it if #1995 is the way forward, or feel free to take a look in case anything with regards to how I implemented it may be helpful. :)

@deepyaman
Copy link

@alexcjohnson @T4rk1n plotly/jupyter-dash#83 is a very similar issue. I've tried to use #1995 as the basis for a similar proposed fix in plotly/jupyter-dash#82.

The other possibility is to not reimplement the logic over there, and refactor the _get_skip bit to be exposed in plotly/dash and use that in plotly/jupyter-dash.

@noble-g
Copy link

noble-g commented Mar 6, 2023

I'm facing a similar issue here. Whenever I try to import jupyter_dash or dash itself in jupyter notebook or jupyterlab, I get the error ImportError: cannot import name 'get_current_traceback' from 'werkzeug.debug.tbtools' (C:\Users\USER\Desktop\DASH\juplab1\myenviron\lib\site-packages\werkzeug\debug\tbtools.py)

I've tried to downgrade the werkzeug version from 2.2.3 to 2.0.0 as suggested by the initial poster here by running pip install Werkzeug==2.0.0 on command prompt.
I saw a lot of comments advising to replace get_current_traceback with DebugTraceback but I couldn't apply such as the error generated from trying to import jupyter_dash and dash.
I also tried

try:
   from werkzeug.debug.tbtools import DebugTraceback
except ImportError:  # temporary fallback for werkzeug<2.1
   from werkzeug.debug.tbtools import get_current_traceback as DebugTraceback

and

from werkzeug.debug.tbtools import DebugTraceback
``` but still got the same error


I think the problem surged from different dash dependencies not having compatible versions.
I will be happy to provide more information, please I need this ASAP as the due date for the project is close by

@alexcjohnson
Copy link
Collaborator

alexcjohnson commented Mar 7, 2023

@noble-g versions of Dash since 2.3.1 that include the fix for this in #1995 don’t import get_current_traceback directly anymore, so I strongly suspect you have an old version of dash installed in your Jupyter env. You should be able to run !pip install --upgrade dash from a code cell in a notebook to ensure you’re upgrading the right one, it’s easy for this to be different from the env in a terminal.

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