0

I am attempting to write a Hello World program in Manim.

I have installed Manim and its prerequisite programs, and can run the sample code from the command prompt as intended. This sample code operates in an unusual way; the user issues a command specifying not only a .py file, but also a single class within it, and Python executes the class definition code, seemingly without instantiating the class.

Now I'm trying to write a standalone .py file that works by instantiating a class when run (I am running it in Visual Studio Community 2019), rather than requiring external commands.

I have checked many of the Similar Questions, but unfortunately, they are all about Hello World programs in general, even spanning many non-Python languages.

I found a few AttributeError: '____' object has no attribute '____' questions in search, including this helpful explanation (https://stackoverflow.com/a/8696339/2364796), but nothing that seems to apply to the code I've explicitly written.

I also checked in IRC, and it was suggested that the problem is triggered within the imported code. However, the same code functions properly when imported into the sample, so I must be working with it incorrectly.

This is the current code for my Hello World program.

from manimlib.imports import *

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

scene1 = Scene()
readthrough = GreetingScript(scene1)

This is the error message produced by the above code.

Media will be stored in ./media\. You can change this behavior by writing a 
diff
erent directory to media_dir.txt.
Traceback (most recent call last):
  File "C:\Users\Admin\Documents\Visual Studio 
2019\Projects\PythonApplication1\
PythonApplication1\PythonApplication1.py", line 8, in <module>
    scene1 = Scene()
  File "C:\Users\Admin\PortableApps\manim-0.1.5\manimlib\scene\scene.py", 
line 3
7, in __init__
    self, **self.file_writer_config,
  File "C:\Users\Admin\PortableApps\manim- 
0.1.5\manimlib\scene\scene_file_writer
.py", line 44, in __init__
    self.init_output_directories()
  File "C:\Users\Admin\PortableApps\manim- 
0.1.5\manimlib\scene\scene_file_writer
.py", line 49, in init_output_directories
    output_directory = self.output_directory or 
self.get_default_output_director
y()
  File "C:\Users\Admin\PortableApps\manim- 
0.1.5\manimlib\scene\scene_file_writer
.py", line 80, in get_default_output_directory
    filename = os.path.basename(self.input_file_path)
AttributeError: 'SceneFileWriter' object has no attribute 'input_file_path'
Press any key to continue . . .

I would expect the output of the program to be a display of the text "Hello World!" but the actual output is AttributeError: 'SceneFileWriter' object has no attribute 'input_file_path' accompanied by the rest of the above message.

4

2 回答 2

1

The best way to solve this problem is to remove the code that creates the scene1 object. To make this code work, it is required to implement only the source of your scene class, and you can generate the scene using:

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

The -p flag means to open the video after rendering the scene. I hope this can help on your issue.

于 2019-09-17T11:35:19.213 回答
-1
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)

have you tried something?

于 2019-06-13T19:51:56.513 回答