Randomly getting “ValueError: PyCapsule_New called with null pointer” when making plots with Python 3.12 fresh install on new PC

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật