(matplotlib LaTex)RuntimeError: Failed to process string with tex because latex could not be found

matplotlib LaTex

在matplotlib里,可以使用LaTex对复杂数学公式、数学符号和文本特定格式进行渲染,如"textbf{time}“和"textit{weight}”。

windows系统下的安装步骤:

第一步:安装MiKTeX;
第二步:安装dviping(a DVI-to-PNG convert):MiKTeX中的miktex包含安装程序dviping.exe,在路径"bin/x64/dvipng.exe"下;
第三部:安装Ghostscript
安装完成后需要进行一些必要的软件安装和PATH环境变量的配置。

mac系统下的安装步骤:

第一步:安装python模块latex:pip3 install latex
第二步:安装latex环境MacTex:brew install mactex 或者直接在官网下载安装包

  1. 查看是否安装成功 latex --version或者which latex
  2. latex的使用参考文档

第三步:MacTex安装成功后打开Tex Live Utility app然后将里面可更跟新的全部更新。参考文档

关于报错:

本机系统及python版本:macOS、3.9.8
报错:RuntimeError: Failed to process string with tex because latex could not be found
其他系统参考以下文章,大概的意思latex未成功安装,以及他的依赖dvipng、cm-super等:
https://blog.csdn.net/weixin_42419002/article/details/103997521 异常处理
http://nicethemes.cn/news/txtlist_i101534v.html 异常处理

MacOS 当用Pycharm或者Jupyter运行时会报“RuntimeError: latex was not able to process the following string:”及相关运行log。但是在终端运行py是报如下信息"MatplotlibDeprecationWarning: Support for setting an rcParam that expects a str value to a non-str value is deprecated since 3.5 and support will be removed two minor releases later."
那问题就出来了:Matplotlib在3.5及以后版本将text.latex.preamble、text.usetex移除了,所以下面两行代码并不会生效:
rcParams[“text.latex.preamble”] = [r"\usepackage{amsmath}"]
rcParams[“text.usetex”] = True

解决方案:

第一步:安装pyenv并用安装python3.7,pyenv使用参考文档,也可以用anaconda。

brew install pyenv

第二步:在python3.7下安装matplotlib==2.2.3

/安装路径/python -m pip install matplotlib==2.2.3

第三步:在pycharm中添加解释器或者直接用命令运行。解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值