0

I'm trying to write a program that edits a video using the moviepy module in python. I have this

#!/usr/bin/env python

import os
import math
import moviepy as mp
import mediainfo

class Editor:

    OFFSET = 2 #seconds


    def __init__(self, identified_frames, options, *args, **kwargs):
        self.movie_path = options.video_path
        self.video = mp.editor.VideoFileClip(self.movie_path)
        #Get the FPS of the input movie and round the number up
        self.movie_fps = math.ceil(mediainfo.get_fps(self.movie_fps))
...

but for some reason this throws this error:

Traceback (most recent call last):
  File "editor.py", line 179, in <module>
    editor = Editor(args["video"], options)
  File "editor.py", line 16, in __init__
    self.video = mp.editor.VideoFileClip(self.movie_path)
AttributeError: 'module' object has no attribute 'editor'

which is strange because according to this documentation definitely exists. What is even weirder is that when I open up my python interpreter, I can do this with no problem:

In [1]: import moviepy

In [2]: import moviepy.editor

In [3]: import moviepy as mp

In [4]: mp.editor
Out[4]: <module 'moviepy.editor' from '/usr/local/lib/python2.7/site-packages/moviepy/editor.pyc'>

In [5]: mp.editor.VideoFileClip
Out[5]: <class moviepy.video.io.VideoFileClip.VideoFileClip at 0x1046bca10>

So the moviepy module definitely contains editor.VideoFileClip. What would cause this error to be thrown in my program if it works in my interpreter? Do I have some environment variables set wrong or something? Any help would be greatly appreciated.

This is what I've done: I have python2 and python3 installed installed but made sure both the interpreter and the program were being run with python2. I also tried reinstalling moviepy but that didn't do anything. I also went and looked through the source code to make sure that the function actually existed (it does).

Update:

This is a duplicate of this question. The best answer says

This happens because the scipy module doesn't have any attribute named sparse. That attribute only gets defined when you import scipy.sparse.

Submodules don't automatically get imported when you just import scipy; you need to import them explicitly. The same holds for most packages, although a package can choose to import its own submodules if it wants to. (For example, if scipy/init.py included a statement import scipy.sparse, then the sparse submodule would be imported whenever you import scipy.)

Which leads me to change my question to why does python work this way? Is there a benefit?

Community
  • 1
  • 1
guribe94
  • 1,551
  • 3
  • 15
  • 29

0 Answers0