如何修复Manim Hello World程序中的AttributeError?

2024-09-27 00:13:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图用Manim编写一个Hello World程序。在

我已经安装了Manim及其必备程序,并且可以根据需要从命令提示符运行示例代码。这个示例代码以一种不寻常的方式运行;用户发出一个命令,不仅指定一个.py文件,而且指定其中的一个类,Python执行类定义代码,似乎没有实例化该类。在

现在我尝试编写一个独立的.py文件,它在运行时实例化一个类(我在VisualStudioCommunity2019中运行它),而不是需要外部命令。在

我已经检查了许多类似的问题,但不幸的是,它们都是关于helloworld程序的,甚至跨越了许多非Python语言。在

我发现了一些AttributeError:'\\'object has no attribute'\\'问题在搜索中,包括这个有用的解释(https://stackoverflow.com/a/8696339/2364796),但似乎没有适用于我显式编写的代码。在

我还检查了IRC,有人建议问题是在导入的代码中触发的。但是,当导入到示例中时,相同的代码可以正常工作,因此我必须不正确地处理它。在

这是我的Hello World程序的当前代码。在

from manimlib.imports import *

class GreetingScript(Scene):
    def construct(self):
        characters = TextMobject("Hello World!")
        self.add(characters)

scene1 = Scene()
readthrough = GreetingScript(scene1)

这是由上述代码产生的错误消息。在

^{pr2}$

我希望程序的输出是文本“helloworld!”的显示但实际的输出是AttributeError:“SceneFileWriter”对象没有属性“input_file_path”以及上面的其余消息。在


Tags: 文件实例代码pyself程序示例hello
2条回答
from big_ol_pile_of_manim_imports import *

class makeText(Scene):
    def construct(self):
        #######Code#######
        #Making text
        first_line = TextMobject("Manim is fun")
        second_line = TextMobject("and useful")
        final_line = TextMobject("Hope you like it too!", color=BLUE)
        color_final_line = TextMobject("Hope you like it too!")

        #Coloring
        color_final_line.set_color_by_gradient(BLUE,PURPLE)

        #Position text
        second_line.next_to(first_line, DOWN)

        #Showing text
        self.wait(1)
        self.play(Write(first_line), Write(second_line))
        self.wait(1)
        self.play(FadeOut(second_line), ReplacementTransform(first_line, final_line))
        self.wait(1)
        self.play(Transform(final_line, color_final_line))
        self.wait(2)

你试过什么吗?在

解决这个问题的最好方法是删除创建scene1对象的代码。要使此代码工作,需要仅实现场景类的源代码,并且可以使用以下方法生成场景:

$ python -m manim -p /path/to/source.py GreetingScript

-p标志表示渲染场景后打开视频。我希望这能对你的问题有所帮助。在

相关问题 更多 >

    热门问题