admin管理员组

文章数量:1123664

I am having trouble running my code. I never encountered this error before (a few months ago) when I wrote the code, I was even able to obtain my plot. However, when I tried running it again yesterday, I suddenly encountered errors (see below).


THIS IS MY CODE ` import importlib

import pandas as pd import numpy as np import scienceplots

import sys from pathlib import Path from scipy import signal

import matplotlib.pyplot as plt

import matplotlib.ticker as ticker import matplotlib.gridspec as gridspec`


THESE ARE THE ERRORS

FileNotFoundError                         Traceback (most recent call last)
Cell In[18], line 42
     38 plt.xticks(fontsize=6)
     39 plt.yticks(fontsize=6)
---> 42 plt.savefig("7_cT.png", dpi=600)
     43 plt.savefig("7_cT.svg", dpi=300)
     44 plt.tight_layout()

File c:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\matplotlib\pyplot.py:1243, in savefig(*args, **kwargs)
   1240 fig = gcf()
   1241 # savefig default implementation has no return, so mypy is unhappy
   1242 # presumably this is here because subclasses can return?
-> 1243 res = fig.savefig(*args, **kwargs)  # type: ignore[func-returns-value]
   1244 fig.canvas.draw_idle()  # Need this if 'transparent=True', to reset colors.
   1245 return res

File c:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\matplotlib\figure.py:3490, in Figure.savefig(self, fname, transparent, **kwargs)
   3488     for ax in self.axes:
   3489         _recursively_make_axes_transparent(stack, ax)
-> 3490 self.canvas.print_figure(fname, **kwargs)

File c:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\matplotlib\backend_bases.py:2155, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2152     # we do this instead of `self.figure.draw_without_rendering`
   2153     # so that we can inject the orientation
...
--> 343     raise self._missing_font.to_exception()
    344 name = self._dtable[byte].__name__
    345 if name == "_push":

FileNotFoundError: Matplotlib's TeX implementation searched for a file named 'cmr6.tfm' in your texmf tree, but could not find it
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File ~\AppData\Roaming\Python\Python313\site-packages\IPython\core\formatters.py:402, in BaseFormatter.__call__(self, obj)
    400     pass
    401 else:
--> 402     return printer(obj)
    403 # Finally look for special method names
    404 method = get_real_method(obj, self.print_method)

File ~\AppData\Roaming\Python\Python313\site-packages\IPython\core\pylabtools.py:170, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
    167     from matplotlib.backend_bases import FigureCanvasBase
    168     FigureCanvasBase(fig)
--> 170 fig.canvas.print_figure(bytes_io, **kw)
    171 data = bytes_io.getvalue()
    172 if fmt == 'svg':

File c:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\matplotlib\backend_bases.py:2155, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2152     # we do this instead of `self.figure.draw_without_rendering`
   2153     # so that we can inject the orientation
   2154     with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2155         self.figure.draw(renderer)
   2156 if bbox_inches:
   2157     if bbox_inches == "tight":

File c:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\matplotlib\artist.py:94, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
...
--> 343     raise self._missing_font.to_exception()
    344 name = self._dtable[byte].__name__
    345 if name == "_push":

FileNotFoundError: Matplotlib's TeX implementation searched for a file named 'ptmr7t.tfm' in your texmf tree, but could not find it
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

I tried downgrading Python, uninstalling and reinstalling it, updating packages, etc. I also found suggestions stating that I need to use sudo install texlive-full. I attempted to install it, but the process took too long and eventually ended with an error.

本文标签: pythonFileNotFoundError using matplotlibpyplot and scienceplots importsStack Overflow