|
22 | 22 | TimerBase,ToolContainerBase,cursors,_Mode,MouseButton, |
23 | 23 | CloseEvent,KeyEvent,LocationEvent,MouseEvent,ResizeEvent) |
24 | 24 | frommatplotlib._pylab_helpersimportGcf |
25 | | -from .import_tkagg |
26 | | -from ._tkaggimportTK_PHOTO_COMPOSITE_OVERLAY,TK_PHOTO_COMPOSITE_SET |
| 25 | + |
| 26 | +try: |
| 27 | +from .import_tkagg |
| 28 | +from ._tkaggimportTK_PHOTO_COMPOSITE_OVERLAY,TK_PHOTO_COMPOSITE_SET |
| 29 | +exceptImportErrorase: |
| 30 | +# catch incompatibility of python-build-standalone with Tk |
| 31 | +cause1=getattr(e,'__cause__',None) |
| 32 | +cause2=getattr(cause1,'__cause__',None) |
| 33 | +if (isinstance(cause1,ImportError)and |
| 34 | +isinstance(cause2,AttributeError)and |
| 35 | +"'_tkinter' has no attribute '__file__'"instr(cause2)): |
| 36 | + |
| 37 | +is_uv_python="/uv/python"in (os.path.realpath(sys.executable)) |
| 38 | +ifis_uv_python: |
| 39 | +raiseImportError( |
| 40 | +"Failed to import tkagg backend. You appear to be using an outdated " |
| 41 | +"version of uv's managed Python distribution which is not compatible " |
| 42 | +"with Tk. Please upgrade to the latest uv version, then update " |
| 43 | +"Python with: `uv python upgrade --reinstall`" |
| 44 | + )frome |
| 45 | +else: |
| 46 | +raiseImportError( |
| 47 | +"Failed to import tkagg backend. This is likely caused by using a " |
| 48 | +"Python executable based on python-build-standalone, which is not " |
| 49 | +"compatible with Tk. Recent versions of python-build-standalone " |
| 50 | +"should be compatible with Tk. Please update your python version " |
| 51 | +"or select another backend." |
| 52 | + )frome |
| 53 | +else: |
| 54 | +raise |
27 | 55 |
|
28 | 56 |
|
29 | 57 | _log=logging.getLogger(__name__) |
|