Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands working in terminal but giving segmentation fault error in python script. #1210

Closed
arpitem opened this issue May 31, 2020 · 4 comments
Labels
question Questions regarding functionality, usage

Comments

@arpitem
Copy link

arpitem commented May 31, 2020

Hi everyone, I have installed moviepy, recently, and was trying to run the example in the following blog to make a gif using mayavi and moviepy packages:
http://zulko.github.io/blog/2014/11/29/data-animations-with-python-and-moviepy/
Code:

import numpy as np
import mayavi.mlab as mlab
import moviepy.editor
from moviepy.editor import VideoClip

duration= 2 # duration of the animation in seconds (it will loop)

# MAKE A FIGURE WITH MAYAVI
fig_myv = mlab.figure(size=(220,220), bgcolor=(1,1,1))
X, Y = np.linspace(-2,2,200), np.linspace(-2,2,200)
XX, YY = np.meshgrid(X,Y)
ZZ = lambda d: np.sinc(XX**2+YY**2)+np.sin(XX+d)

# ANIMATE THE FIGURE WITH MOVIEPY, WRITE AN ANIMATED GIF
def make_frame(t):
mlab.clf() # clear the figure (to reset the colors)
mlab.mesh(YY,XX,ZZ(2**np.pit/duration), figure=fig_myv)
return mlab.screenshot(antialiased=True)

animation = VideoClip(make_frame, duration=duration)
animation.write_gif("sinc.gif", fps=20)

I am able to run the above commands in the terminal without any issue but when I am trying to run it using the script (python gif.py) I am getting a segmentation fault error. I am using the same version of python on my system for both the script and for running commands on the terminal. The following is the error thread using the fault handler:

Current thread 0x00007f2adf7cf700 (most recent call first):
File "/home/multismart/.local/lib/python3.5/site-packages/tvtk/tvtk_base.py", line 594 in _wrap_call
File "tvtk_classes/open_gl_render_window.py", line 117 in get_pixel_data
File "/home/multismart/.local/lib/python3.5/site-packages/mayavi/tools/figure.py", line 340 in screenshot
File "mayavi_gif.py", line 21 in make_frame
File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 93 in get_frame
File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89 in wrapper
File "<decorator-gen-18>", line 2 in get_frame
File "/usr/local/lib/python3.5/dist-packages/moviepy/video/VideoClip.py", line 86 in init
File "mayavi_gif.py", line 22 in <module>
Segmentation fault (core dumped)

Can someone point out what I am doing wrong in running the script compare to running the same commands on the terminal?

@arpitem arpitem added the question Questions regarding functionality, usage label May 31, 2020
@tburrows13
Copy link
Collaborator

Sorry, I tried to install mayavi to test your script, but for some reason I can't get it to install on macOS.

@arpitem
Copy link
Author

arpitem commented May 31, 2020

Thank you for trying. I have checked, separately, mayavi and moviepy package and the examples are working in both cases (terminal and running script). Do you have any suggestions or guess "Why the behavior is different in the shell(works in the shell) as opposed to running the python script(segmentation fault error) in the terminal for the above code? "

@tburrows13
Copy link
Collaborator

Well its not much help, but #223 is exactly the same. No solution there though.

@arpitem
Copy link
Author

arpitem commented Jun 1, 2020

The above problem is related to mayavi rather than moviepy. I found that it is related to error in mlab.screenshot() value error: enthought/mayavi#702
Adding the following lines in the above code solved the problem

f =mlab.gcf()
f.scene._lift()

@arpitem arpitem closed this as completed Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions regarding functionality, usage
Projects
None yet
Development

No branches or pull requests

2 participants