python - Cannot save animation in matplotlib: Windows permission denied -


i've been trying day long sort out, checking similar threads no success. stretch's cannot save matplotlib animation ffmpeg helped previous errors (i had ffmpeg path wrong), kept getting access denied after fixing it.

my ffmpeg binary on c:\ffmpeg\bin

a nice alternative able export gif files, keep getting ascii error imagemagick. think both problems related, wanted sort out ffmpeg first.

i think problem might have fact i'm working canopy (in windows 8 64bit), pretty hegemonized path variable , broke things along way (e.g. can't open idle since installed canopy, didn't tried fix yet). fixed things along way found @ least 3 distinct path variables, of updated: windows advanced settings path (set manually), windows console path (set via console setx), , sys.path (set or checked @ runtime), adding ";c:\ffmpeg\bin", ffmpeg is. regardless sort out problem or not, learn of these environment variables relevant what, find confusing.

the code following:

# -*- coding: utf-8 -*- import sys import numpy np matplotlib import pyplot plt matplotlib import animation plt.rcparams['animation.ffmpeg_path'] = r'c:\ffmpeg\bin' if r'c:\ffmpeg\bin' not in sys.path: sys.path.append(r'c:\ffmpeg\bin')  fig = plt.figure() ax = plt.axes(xlim=(0, 2), ylim=(-2, 2)) line, = ax.plot([], [], lw=2)  def init():     line.set_data([], [])     return line,  def animate(i):     x = np.linspace(0, 2, 1000)     y = np.sin(2 * np.pi * (x - 0.01 * i))     line.set_data(x, y)     return line,  anim = animation.funcanimation(fig, animate, init_func=init, frames=200, interval=20, blit=true) plt.show()  # case generates windows err: access denied ffwriter = animation.ffmpegwriter() # anim.save(r'c:\basic_animation.mp4', writer = ffwriter, fps=30)  # case generates unicodedecodeerror:'ascii' codec can't decode byte 0xa0 in position 3 # anim.save(r'c:\animation.gif', writer='imagemagick', fps=30) 

the traceback anim.save(r'c:\basic_animation.mp4', writer = ffwriter, fps=30):

%run "c:\users\yahveh\documents\vlad\investigacion\animation saving.py" --------------------------------------------------------------------------- windowserror                              traceback (most recent call last) c:\users\yahveh\documents\vlad\investigacion\animation saving.py in <module>()      27 # case generates windows err: access denied      28 ffwriter = animation.ffmpegwriter() ---> 29 anim.save(r'c:\basic_animation.mp4', writer = ffwriter, fps=30)      30       31 # case generates unicodedecodeerror:'ascii' codec can't decode byte 0xa0 in position 3  c:\users\yahveh\appdata\local\enthought\canopy\user\lib\site-packages\matplotlib\animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)     759         # since gui widgets gone. either need remove code     760         # allow non-existant use case or find way make work. --> 761         writer.saving(self._fig, filename, dpi):     762             data in zip(*[a.new_saved_frame_seq()     763                               in all_anim]):  c:\users\yahveh\appdata\local\enthought\canopy\app\appdata\canopy-1.5.2.2785.win-x86_64\lib\contextlib.pyc in __enter__(self)      15     def __enter__(self):      16         try: ---> 17             return self.gen.next()      18         except stopiteration:      19             raise runtimeerror("generator didn't yield")  c:\users\yahveh\appdata\local\enthought\canopy\user\lib\site-packages\matplotlib\animation.pyc in saving(self, *args)     184         '''     185         # particular sequence contextlib.contextmanager wants --> 186         self.setup(*args)     187         yield     188         self.finish()  c:\users\yahveh\appdata\local\enthought\canopy\user\lib\site-packages\matplotlib\animation.pyc in setup(self, fig, outfile, dpi, *args)     174         # run here grab_frame() can write data pipe.     175         # eliminates need temp files. --> 176         self._run()     177      178     @contextlib.contextmanager  c:\users\yahveh\appdata\local\enthought\canopy\user\lib\site-packages\matplotlib\animation.pyc in _run(self)     202                                       stdout=output, stderr=output,     203                                       stdin=subprocess.pipe, --> 204                                       creationflags=subprocess_creation_flags)     205      206     def finish(self):  c:\users\yahveh\appdata\local\enthought\canopy\app\appdata\canopy-1.5.2.2785.win-x86_64\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)     707                                 p2cread, p2cwrite,     708                                 c2pread, c2pwrite, --> 709                                 errread, errwrite)     710         except exception:     711             # preserve original exception in case os.close raises.  c:\users\yahveh\appdata\local\enthought\canopy\app\appdata\canopy-1.5.2.2785.win-x86_64\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)     955                                          env,     956                                          cwd, --> 957                                          startupinfo)     958             except pywintypes.error, e:     959                 # translate pywintypes.error windowserror,  windowserror: [error 5] acceso denegado  

the traceback anim.save(r'c:\animation.gif', writer='imagemagick', fps=30):

in [8]: %run "c:\users\yahveh\documents\vlad\investigacion\animation saving.py" --------------------------------------------------------------------------- unicodedecodeerror                        traceback (most recent call last) c:\users\yahveh\documents\vlad\investigacion\animation saving.py in <module>()      30       31 # case generates unicodedecodeerror:'ascii' codec can't decode byte 0xa0 in position 3 ---> 32 anim.save(r'c:\animation.gif', writer='imagemagick', fps=30)  c:\users\yahveh\appdata\local\enthought\canopy\user\lib\site-packages\matplotlib\animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)     765                     # todo: need see if turning off blit necessary     766                     anim._draw_next_frame(d, blit=false) --> 767                 writer.grab_frame(**savefig_kwargs)     768      769         # reconnect signal first draw if necessary  c:\users\yahveh\appdata\local\enthought\canopy\user\lib\site-packages\matplotlib\animation.pyc in grab_frame(self, **savefig_kwargs)     225             verbose.report('moviewriter -- error '     226                            'running proc:\n%s\n%s' % (out, --> 227                                                       err), level='helpful')     228             raise     229   unicodedecodeerror: 'ascii' codec can't decode byte 0xa0 in position 3: ordinal not in range(128)  

stared @ them while.

thanks time!

update: followed steps in this post granting access both c:\ffmpeg , destination folder, no luck :(

try saving files somewhere else, debugging purposes. is: you're saving "c:\basic_animation.mp4", try "c:\temp\basic_animation.mp4".

if remember right, win7+ added security in "c:\" , other directories. simple test tell if problem destination directory or not.

i'll recomend use system's temp dir kind of things, , moving file should go. can tue current system's temp dir in python this:

import tempfile  print tempfile.gettempdir() 

also, "'ascii' codec can't decode" problem: it's string conversion problem. happens time, specially on windows.

check out: http://nedbatchelder.com/text/unipain/unipain.html#1

but time seems inside ffmpeg's, "anim" instance returned "funcanimation", , don't see wrongdoing on use. best thing can guarantee strings correctly converted before being used. path strings, example.

here's comment that: https://stackoverflow.com/a/21129492

for can understand of stack trace, string conversion error happening in verbose/log function inside canopy. perhaps trying log non-ascii chars. so, try canopy flag log/verbose disabling; maybe that's enough.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -