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

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

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

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

本机系统及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

brew install pyenv

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

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

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

Original: https://blog.csdn.net/qq_15546921/article/details/122896540
Author: Beisi_x
Title: (matplotlib LaTex)RuntimeError: Failed to process string with tex because latex could not be found

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/764393/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球