I use a suite of python 3.7 code for my work, generating various plots and fitting lines. It works perfectly fine on my old windows 10 machine.
However, I just got a new laptop and installed 3.12 on it. The code still works, but SOMETIMES it randomly decides to fail on a plot, giving “ValueError: PyCapsule_New called with null pointer” originating from a simple line of code that I use to initialize new plots: plt.figure(figsize=(figx,figy)) #generate clean figure
.
I can see no rhyme or reason as to why it sometimes works and occasionally fails. In a few instances, I’ve literally just changed the order of certain plots and it works just fine. In others, I change minor details like the initial guess for the center of a gaussian for a line fit (by one index), and it works just fine all of a sudden.
I’m at a loss as to how to move forward with this, as the problem seems to be some random, arcane issue buried deep within matplotlib or python or something, clearly relating to something with the fresh install on my new machine.
Any suggestions?
Full error below:
File "D:astraASTRA MSMassify.py", line 435, in <module>
ASTRA_MS.plot_set(x_m,t,y_ms,y_blur,y_superblur,y_megablur,figtext,titletext,shotnum,plotstyle=plotstyle,savepath=path,falling=falling,vlines=vlines,vacc=vacc,xlim=xlim,showplots=showplots,invertplot=invertplot,metadata=str(values))
File "D:astraASTRA MSASTRA_MS.py", line 259, in plot_set
plt.figure(figsize=(figx,figy)) #generate clean figure
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibpyplot.py", line 1022, in figure
manager = new_figure_manager(
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibpyplot.py", line 545, in new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibbackend_bases.py", line 3521, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibbackend_bases.py", line 3526, in new_figure_manager_given_figure
return cls.FigureCanvas.new_manager(figure, num)
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibbackend_bases.py", line 1811, in new_manager
return cls.manager_class.create_with_canvas(cls, figure, num)
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibbackends_backend_tk.py", line 479, in create_with_canvas
with _restore_foreground_window_at_end():
File "C:Program FilesPython312Libcontextlib.py", line 137, in __enter__
return next(self.gen)
File "C:UserszachuAppDataRoamingPythonPython312site-packagesmatplotlibbackends_backend_tk.py", line 43, in _restore_foreground_window_at_end
foreground = _c_internal_utils.Win32_GetForegroundWindow()
ValueError: PyCapsule_New called with null pointer