How can I fix AttributeError in Manim Hello World program? - python

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.

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.

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?

Related

What causes this Attribute Error encountered when implementing LangChain's OpenAI LLM wrapper?

This is my first post here. I'm building a Python window application with PyQt5 that implements interactions with the OpenAI completions endpoint. So far, any code that I've written myself has performed fine, and I was reaching the point where I wanted to start implementing long-term memory for conversational interactions. I started by just running my own chain of prompts for categorizing and writing topical subjects and summaries to text files, but I decided it best to try exploring open source options to see how the programming community is managing things. This led me to LangChain, which seems to have some popular support behind it and already implements many features that I intend.
However, I have not had even the tiniest bit of success with it yet. Even the most simple examples don't perform, regardless of what context I'm implementing it in (within a class, outside a class, in an asynchronous loop, to the console, to my text browsers within the main window, whatever) I always get the same error message.
The simplest possible example:
import os
from langchain.llms import OpenAI
from local import constants #For API key
os.environ["OPENAI_API_KEY"] = constants.OPENAI_API_KEY
davinci = OpenAI(model_name= 'text-davinci-003', verbose=True, temperature=0.6)
text = "Write me a story about a guy who is frustrated with Python."
print("Prompt: " + text)
print(davinci(text))
It capably instantiates the wrapper and prints the prompt to the console, but at any point a command is sent through the wrapper's functions to receive generated text, it encounters this AttributeError.
Here is the traceback:
Traceback (most recent call last):
File "D:\Dropbox\Pycharm Projects\workspace\main.py", line 16, in <module>
print(davinci(text))
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\base.py", line 255, in __call__
return self.generate([prompt], stop=stop).generations[0][0].text
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\base.py", line 128, in generate
raise e
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\base.py", line 125, in generate
output = self._generate(prompts, stop=stop)
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\openai.py", line 259, in _generate
response = self.completion_with_retry(prompt=_prompts, **params)
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\openai.py", line 200, in completion_with_retry
retry_decorator = self._create_retry_decorator()
File "D:\Dropbox\Pycharm Projects\workspace\venv\lib\site-packages\langchain\llms\openai.py", line 189, in _create_retry_decorator
retry_if_exception_type(openai.error.Timeout)
AttributeError: module 'openai.error' has no attribute 'Timeout'
I don't expect that there is a fault in the LangChain library, because it seems like nobody else has experienced this problem. I imagine I may have some dependency issue? Or I do notice that others using the LangChain library are doing so in a notebook development environment, and my lack of familiarity in that regard is making me overlook some fundamental expectation of the library's use?
Any advice is welcome! Thanks!
What I tried: I initially just replaced my own function for managing calls to the completion endpoint with one that issued the calls through LangChain's llm wrapper. I expected it to work as easily as my own code had, but I received that error. I then stripped everything apart layer by layer attempting to instantiate the wrapper at every scope of the program, then I attempted to make the calls in an asynchronous function through a loop that waited to completion, and no matter what, I always get that same error message.
I think it might be something about your current installed versions of Python, OpenAI, and/or LangChain. Maybe try using a newer version of Python and OpenAI. I'm new to Python and these things but hopefully I could help.

Tkinter python GUI trouble with module and __init__

so I found this program, "BoxParti" made by user tpvasconcelos and I think it could help me greatly with research. Sadly it uses some packages I have never used before and it's kinda problematic to get it to work for me. I didn't change anything in the code but it doesn't want to work with me. Problem is mainly with tkinter and i'm not really familiar with it. I never used GUI before so it's kinda all tricky to me. At the moment I only want to make the program work and check if it could really be useful for me. I've been trying to make it work by myself but I didn't suceed sadly. It's kinda complex for me since I haven't used python in a while + haven't really ever used GUI with anything. Below I paste the link to download the code. I run it on Python 3.8 or 2.7, on both versions i get same errors. Below the link I paste error logs. I would greatly appreciate any tip that could sort of push me in the right direction because it seems to me I'm very lost
https://github.com/TPVasconcelos/BoxParti
Traceback (most recent call last):
File "BoxParti.py", line 1493, in <module>
app = BoxParti()
File "BoxParti.py", line 53, in __init__
frame = F(container, self)
File "BoxParti.py", line 151, in __init__
self.make_plot(frame)
File "BoxParti.py", line 176, in make_plot
self.canvas.show()
AttributeError: 'FigureCanvasTkAgg' object has no attribute 'show'
This code may work in early versions of Python, e.g. python 3.5. Several things have been deprecated. That means, you have to find correct packages.
For instance, if you uncomment the following the code runs on Python 3.8.
Uncomment: #self.canvas.show() in lines; 177, 610, 646, 692, 817, 1268, 1299, 1371
also uncomment; self.canvas.get_tk_widget()#.grid(row=0, column=1), in lines 179, 819.
But it does not show 2D or 3D anime. This could be because of uncommenting self.canvas.show().
As a result, if you want to run this code, you have to find older versions required libraries. Which I do not suggest.
Instead of that, BoxParti have been expanded to mdsea, you can install mdsea which may work better.

NameError: global name 'imshow' is not defined but Matplotlib is imported

I'm currently writing a python script which plots a numpy matrix containing some data (which I'm not having any difficulty computing). For complicated reasons having to do with how I'm creating that data, I have to go through terminal. I've done problems like this a million times in Spyder using imshow(). So, I thought I'd try to do the same in terminal. Here's my code:
from numpy import *
from matplotlib import *
def make_picture():
f = open("DATA2.txt")
arr = zeros((200, 200))
l = f.readlines()
for i in l:
j = i[:-1]
k = j.split(" ")
arr[int(k[0])][int(k[1])] = float(k[2])
f.close()
imshow(arr)
make_picture()
Suffice it to say, the array stuff works just fine. I've tested it, and it extracts the data perfectly well. So, I've got this 200 by 200 array of numbers floating around my RAM and I'd like to display it. When I run this code in Spyder, I get exactly what I expected. However, when I run this code in Terminal, I get an error message:
Traceback (most recent call last):
File "DATAmine.py", line 15, in <module>
make_picture()
File "DATAmine.py", line 13, in make_picture
imshow(arr)
NameError: global name 'imshow' is not defined
(My program's called DATAmine.py) What's the deal here? Is there something else I should be importing? I know I had to configure my Spyder paths, so I wonder if I don't have access to those paths or something. Any suggestions would be greatly appreciated. Thanks!
P.S. Perhaps I should mention I'm using Ubuntu. Don't know if that's relevant.
To make your life easier you can use
from pylab import *
This will import the full pylab package, which includes matplotlib and numpy.
Cheers

Can't install trigger network automation tools

I read in the howto documentation to install Trigger, but when I test in python environment, I get the error below:
>>> from trigger.netdevices import NetDevices
>>> nd = NetDevices()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 913, in __init__
with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 767, in __init__
production_only=production_only, with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 83, in _populate
# device_data = _munge_source_data(data_source=data_source)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 73, in _munge_source_data
# return loader.load_metadata(path, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/loader.py", line 163, in load_metadata
raise RuntimeError('No data loaders succeeded. Tried: %r' % tried)
RuntimeError: No data loaders succeeded. Tried: [<trigger.netdevices.loaders.filesystem.XMLLoader object at 0x7f550a1ed350>, <trigger.netdevices.loaders.filesystem.JSONLoader object at 0x7f550a1ed210>, <trigger.netdevices.loaders.filesystem.SQLiteLoader object at 0x7f550a1ed250>, <trigger.netdevices.loaders.filesystem.CSVLoader object at 0x7f550a1ed290>, <trigger.netdevices.loaders.filesystem.RancidLoader object at 0x7f550a1ed550>]
Does anyone have some idea how to fix it?
The NetDevices constructor is apparently trying to find a "metadata source" that isn't there.
Firstly, you need to define the metadata. Second, your code should handle the exception where none is found.
I'm the lead developer of Trigger. Check out the the doc Working with NetDevices. It is probably what you were missing. We've done some work recently to improve the quality of the setup/install docs, and I hope that this is more clear now!
If you want to get started super quickly, you can feed Trigger a CSV-formatted NetDevices file, like so:
test1-abc.net.example.com,juniper
test2-abc.net.example.com,cisco
Just put that in a file, e.g. /tmp/netdevices.csv and then set the NETDEVICES_SOURCE environment variable:
export NETDEVICES_SOURCE=/tmp/netdevices.csv
And then fire up python and continue on with your examples and you should be good to go!
I found that the default of /etc/trigger/netdevices.xml wasn't listed in the setup instructions. It did indicate to copy from the trigger source folder:
cp conf/netdevices.json /etc/trigger/netdevices.json
But, I didn't see how to specify this instead of the default NETDEVICES_SOURCE on the installation page. But, as soon as I had a file that NETDEVICES_SOURCE pointed to in my /etc/trigger folder, it worked.
I recommend this to get the verifying functionality examples to work right away with minimal fuss:
cp conf/netdevices.xml /etc/trigger/netdevices.xml
Using Ubuntu 14.04 with Python 2.7.3

input syntax in paraview python shell

I currently am trying to use
paraview.simple.Histogram(Input, params)
as
paraview.simple.Histogram(q, BinCount = 30)
in the shell where q is a variable data set from my "out.e" ExodusII file. I'm getting the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'q' is not defined
I've tried to search the literature on python shell scripting in Paraview but it seems to be eluding me. I know this is a quick fix. Thanks
Try this instead:
Histogram(SelectInputArray="q", BinCount=30)
This assumes you currently have the reader as the active object in the Pipeline browser.
I was able to answer this problem using the following.
outset = Reader(FileName=['/dir/out.e'])
and for the Histogram
histogram1_1 = Histogram(Input=outset)
histogram1_1.SelectInputArray = ['CELLS', 'q']
histogram1_1.BinCount = 30
Note for anyone who comes into this issue, the TRACE option in the Python Shell will build a script for you when you do anything in the GUI.

Categories