【 Failed to process string with tex because latex could not be found /FileNotFoundError: [Errno 2] 】

由于Python代码中含有 **plt.rc(‘text’,usetex=True);**导致报错

Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py”, line 277, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py”, line 395, in check_output
**kwargs).stdout
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py”, line 472, in run
with Popen(*popenargs, **kwargs) as process:
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py”, line 775, in init
restore_signals, start_new_session)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py”, line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ‘latex’: ‘latex’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/backends/backend_macosx.py”, line 61, in _draw
self.figure.draw(renderer)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/artist.py”, line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/figure.py”, line 1864, in draw
renderer, self, artists, self.suppressComposite)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/image.py”, line 131, in _draw_list_compositing_images
a.draw(renderer)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/artist.py”, line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py”, line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/axes/_base.py”, line 2747, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/image.py”, line 131, in _draw_list_compositing_images
a.draw(renderer)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/artist.py”, line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/axis.py”, line 1166, in draw
renderer)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/axis.py”, line 1092, in _get_tick_bboxes
for tick in ticks if tick.label1.get_visible()],
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/axis.py”, line 1092, in
for tick in ticks if tick.label1.get_visible()],
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/text.py”, line 900, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/text.py”, line 287, in _get_layout
ismath=“TeX” if self.get_usetex() else False)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py”, line 228, in get_text_width_height_descent
s, fontsize, renderer=self)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py”, line 423, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py”, line 311, in make_dvi
texfile], tex)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py”, line 281, in _run_checked_subprocess
‘found’.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found

解决方法:pip/pip3 install latex 后不能解决问题,注释掉plt.rc(‘text’,usetex=True),就不会报错,这一句代码的意思是使用latex,由于latex与Python pip3下载后的latex不是一回事,与Python无法兼容。解决方法是:要么去下载latex专属版本(与Python pip下载无关),要么在Python文件中使用plt.show()去显示图像,建议使用后者。

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值