AttributeError: 'FFmpegWriter' object has no attribute '_proc' - python

I have some problem which i cannot find answer to. After installing scikit-video and FFmpeg i got this error:
AttributeError: 'FFmpegWriter' object has no attribute '_proc'
can you help me to find solution to this.
from skvideo.io import FFmpegWriter
def main():
...
video_writer = FFmpegWriter('video.mp4')
...
if __name__ == '__main__':
main()
Already tried to install pyaudio, reinstall FFmpeg and skvideo and install different versions of packages. Does not help at all.
Edit: an example of the full traceback resulting from /skvideo/io/abstract.py is below.
Traceback (most recent call last):
File "run_modules.py", line 93, in <module>
Pipeline.create_videos(video_attr, args.output_path, args.padded)
File "/home/leuko/.local/lib/python3.6/site-packages/skvideo/io/abstract.py", line 474, in close
if self._proc is None: # pragma: no cover
AttributeError: 'FFmpegWriter' object has no attribute '_proc'

I just ran into this issue, and found that FFmpegWriter was actually masking another error. My code was roughly like this:
with FFmpegWriter('/tmp/tmp.webm') as writer:
for frame in frames:
<code to generate out>
writer.writeFrame(out)
The code block before writer.writeFrame was raising an error, but I didn't see that because I didn't look at the full stack trace. I couldn't figure out why FFmpegWriter was throwing this error, but it made sense once I realized I wasn't actually writing any frames but was then trying to close the writer.

Related

tkintermapview PhotoImage object has no attribute '_PhotoImage__photo'

I am making a project based on tkintermapview, but it throws the error when the following code is run.
import tkintermapview as tkmap
self.map = tkmap.TkinterMapView(self.__map_frame, width=self.__map_width,
height=self.__height, corner_radius=0)
# google normal tile server
self.map.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
# google satellite tile server
# self.map.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
# self.map.set_tile_server("http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.png") # painting style
self.map.pack(fill=tk.BOTH)
self.map.set_address("kathmandu")
if the last line i.e. set_address() is removed then it runs fine otherwise it throws the error.
following is the error message:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Exception ignored in: <function PhotoImage.__del__ at 0x7fa9e10ed510>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Process finished with exit code 0
I tried the following code as well to reproduce the error
from tkintermapview import TkinterMapView
root_tk = tkinter.Tk()
root_tk.geometry(f"{600}x{400}")
root_tk.title("map_view_simple_example.py")
# create map widget
map_widget = TkinterMapView(root_tk, width=600, height=400, corner_radius=0)
map_widget.pack(fill="both", expand=True)
# google normal tile server
map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
map_widget.set_address("chyasal")
root_tk.mainloop()
But this time the error is shown for the first time only. After that the program works correctly.
But again when I change the place to new location say set_address("Manang") again for the first launch, the same error is occured.
But this is not the case with all the places, I tried many different places inside the set_address() method, but only some of them caused the error.
I have one more question
My project should enable a user to pick the pick up and drop off location on the map and the map should calculate the shortest road and its distance(length of road) between the two locations.
Is tkintermapview good choice or is there a better way to display google map and implement this requirement in tkinter...?

Facebook scraper 'NoneType' object has no attribute 'find' while get_post

While i using facebook_scraper libraries to get post from facebook page with this code.
from facebook_scraper import get_posts
for post in get_posts('ThaiPBSFan', pages = 50):
print(post['text'][:100])
It work with few post, then error like this.
Traceback (most recent call last):
File ".\main.py", line 2, in <module>
for post in get_posts('ThaiPBSFan', pages = 50):
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebook_scraper.py", line 75, in _get_posts
yield _extract_post(article)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebook_scraper.py", line 102, in _extract_post
text, post_text, shared_text = _extract_text(article)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebook_scraper.py", line 137, in _extract_text
nodes = article.find('p, header')
AttributeError: 'NoneType' object has no attribute 'find'
So what's a problem and how can i fix it.
From the traceback, it seems that facebook_scraper is not returning a valid post; this may be because there are no further posts to find on the page.
Therefore, you could use a try/except block to catch this exception, i.e.:
try:
for post in get_posts('ThaiPBSFan', pages=50):
print(post['text'][:100])
except AttributeError:
print("No more posts to get")
It's not ideal as you would preferably be able to get a more specific exception once there were no more posts to retrieve, but it should work in your case. Be careful with the code insider your try clause - if an AttributeError is raise anywhere else, you will miss it.
I had the same issue, but only when using the most recent version of the package (0.1.12). Try with an older version of the package. For example, I tried the version 0.1.4 and it worked well. To install it, write:
pip install facebook_scraper==0.1.4
in your terminal.

Python jsonpickle error: 'OrderedDict' object has no attribute '_OrderedDict__root'

I'm hitting this exception with jsonpickle, when trying to pickle a rather complex object that unfortunately I'm not sure how to describe here. I know that makes it tough to say much, but for what it's worth:
>>> frozen = jsonpickle.encode(my_complex_object_instance)
>>> thawed = jsonpickle.decode(frozen)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/jsonpickle/__init__.py",
line 152, in decode
return unpickler.decode(string, backend=backend, keys=keys)
:
:
File "/Library/Python/2.7/site-packages/jsonpickle/unpickler.py",
line 336, in _restore_from_dict
instance[k] = value
File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/packages/ordered_dict.py",
line 49, in __setitem__
root = self.__root
AttributeError: 'OrderedDict' object has no attribute '_OrderedDict__root'
I don't find much of assistance when googling the error. I do see what looks like the same issue was resolved at some time past for simpler objects:
https://github.com/jsonpickle/jsonpickle/issues/33
The cited example in that report works for me:
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict()))
OrderedDict()
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict(a=1)))
OrderedDict([(u'a', 1)])
Has anyone ever run into this themselves and found a solution? I ask with the understanding that my case may be "differently idiosynchratic" than another known example.
The requests module for me seems to be running into problems when I .decode(). After looking at the jsonpickle code a bit, I decided to fork it and change the following lines to see what was going on (and I ended up keeping a private copy of jsonpickle with the changes so I can move forward).
In jsonpickle/unpickler.py (in my version it's line 368), search for the if statement section in the method _restore_from_dict():
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
instance[k] = value
else:
setattr(instance, k, value)
and change it to this (it will logERROR the ones that are failing and then you can either keep the code in place or change your OrderedDict's version that have __root)
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
# Currently requests.adapters.HTTPAdapter is using a non-standard
# version of OrderedDict which doesn't have a _OrderedDict__root
# attribute
try:
instance[k] = value
except AttributeError as e:
import logging
import pprint
warnmsg = 'Unable to unpickle {}[{}]={}'.format(pprint.pformat(instance), pprint.pformat(k), pprint.pformat(value))
logging.error(warnmsg)
else:
setattr(instance, k, value)

TensorFlow with skflow: AttributeError: 'module' object has no attribute 'saver_pb2'

I tried to run the iris_save_restore.py example from skflow, without changing the code at all.
However, I got an error, and I am unsure how to proceed.
It seems that it happened when it restores the model from a saved file.
new_classifier = skflow.TensorFlowEstimator.restore('/tmp/skflow_examples/iris_custom_model')
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
score = metrics.accuracy_score(y_test, new_classifier.predict(X_test))
print('Accuracy: {0:f}'.format(score)) File "/Users/hamayu/.pyenv/versions/anaconda2-2.5.0/lib/python2.7/site-packages/skflow/estimators/base.py", line 463, in restore
estimator._restore(path)
File "/Users/hamayu/.pyenv/versions/anaconda2-2.5.0/lib/python2.7/site-packages/skflow/estimators/base.py", line 401, in _restore
saver_def = tf.python.training.saver_pb2.SaverDef()
AttributeError: 'module' object has no attribute 'saver_pb2'
I use the following versions:
anaconda2-2.5.0
tensorflow 0.7 CPU-only for Mac OS X
skflow 0.1.0
How can I fix it?
This looks like a bug in skflow: the current version of skflow is not compatible with the latest version of TensorFlow (0.7.0 and up). I submitted a pull request to fix it. (EDIT: The pull request has now been merged, so upgrading to the latest version of skflow will also fix things.)
In the meantime, you can fix it by editing line 401 of "skflow/estimators/base.py" (full path in your stacktrace), and replacing:
saver_def = tf.python.training.saver_pb2.SaverDef()
...with:
saver_def = tf.train.SaverDef()
The author just fixed this issue today: https://github.com/tensorflow/skflow/issues/144. You'd have to remove and reinstall skflow from github (the most up-to-date release).

AttributeError: xmlNode instance has no attribute 'isCountNode'

I'm using libxml2 in a Python app I'm writing, and am trying to run some test code to parse an XML file. The program downloads an XML file from the internet and parses it. However, I have run into a problem.
With the following code:
xmldoc = libxml2.parseDoc(gfile_content)
droot = xmldoc.children # Get document root
dchild = droot.children # Get child nodes
while dchild is not None:
if dchild.type == "element":
print "\tAn element with ", dchild.isCountNode(), "child(ren)"
print "\tAnd content", repr(dchild.content)
dchild = dchild.next
xmldoc.freeDoc();
...which is based on the code example found on this article on XML.com, I receive the following error when I attempt to run this code on Python 2.4.3 (CentOS 5.2 package).
Traceback (most recent call last):
File "./xml.py", line 25, in ?
print "\tAn element with ", dchild.isCountNode(), "child(ren)"
AttributeError: xmlNode instance has no attribute 'isCountNode'
I'm rather stuck here.
Edit: I should note here I also tried IsCountNode() and it still threw an error.
isCountNode should read "lsCountNode" (a lower-case "L")

Categories