# -- coding: utf-8 --\nfrom manim import *\nfrom manim import MathTex\nimport sys\nsys.stdin.reconfigure(encoding='utf-8')\nsys.stdout.reconfigure(encoding='utf-8')\n\nclass CircleToSquare(Scene):\n def construct(self):\n equation = MathTex(r"这是一个中文文本")\n self.play(Write(equation))\n self.wait()\n\nif name == "main":\n scene = CircleToSquare()\n scene.render()\n\n这个错误是由于 Manim 尝试读取默认的编码格式(GBK),而输入的文本是 UTF-8 编码所导致的。你可以通过在代码开头添加以下两行来解决这个问题:\n\npython\nimport sys\nsys.stdin.reconfigure(encoding='utf-8')\nsys.stdout.reconfigure(encoding='utf-8')\n\n\n这样就可以正确读取和输出中文文本了。完整的代码如下:\n\npython\n# -*- coding: utf-8 -*-\nfrom manim import *\nfrom manim import MathTex\nimport sys\nsys.stdin.reconfigure(encoding='utf-8')\nsys.stdout.reconfigure(encoding='utf-8')\n\nclass CircleToSquare(Scene):\n def construct(self):\n equation = MathTex(r"这是一个中文文本")\n self.play(Write(equation))\n self.wait()\n\nif __name__ == "__main__":\n scene = CircleToSquare()\n scene.render()\n\n\n希望对你有帮助!

Manim 中显示中文文本的 UnicodeDecodeError 错误解决方法

原文地址: https://www.cveoy.top/t/topic/qzxO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录