AttributeError: 'module' object has no attribute 'audio_fadein'

AttributeError: 'module' object has no attribute 'audio_fadein'

我已经使用 cx_freeze 将 python 项目构建到带有 .exe 及其依赖项的单个文件夹中,但是当我 运行 .exe 时出现错误:

AttributeError: module 'moviepy.audio.fx.all' has no attribute 'audio_fadein'

我已阅读 MoviePy 的文档,但无法找出发生这种情况的原因。我的 Python 程序 运行 完全来自 IDE (PyCharm),但编译后,我收到 MoviePy 错误。我用过推荐的from moviepy.editor import *

我实际上并没有在我的脚本中直接使用 audio_fadein,所以当我显示我的视频时,它必须被 MoviePy 调用。这是代码:

def cherrybyte():
    pygame.display.set_caption('©2017 CherryByte™ Software')
    pygame.mouse.set_visible(False)
    logo = VideoFileClip('CherryByte Logo.mp4')
    logo.preview()
    pygame.mouse.set_visible(True)

编辑:我现在也尝试将导入语句更改为 from moviepy.editor import VideoFileClip 但出现完全相同的错误。

我在使用 pyinstaller 构建 .exe 文件时遇到了同样的错误。 但是,我将导入语句更改为 from moviepy.video.io.VideoFileClip import VideoFileClip 它奏效了。

对于遇到相同问题的每个人,我通过修改下图所示的选定 init 文件解决了这个问题:

File Location

里面有一段代码导入了fx文件夹里面的每一个函数:

__all__ = [name for _, name, _ in pkgutil.iter_modules(
    fx.__path__) if name != "all"]
for name in __all__:
    exec("from ..%s import %s" % (name, name))

评论此块并手动导入所需的每个函数,如下所示:

from moviepy.video.fx.accel_decel import accel_decel
from moviepy.video.fx.blackwhite import blackwhite
from moviepy.video.fx.blink import blink
from moviepy.video.fx.crop import crop
from moviepy.video.fx.even_size import even_size
from moviepy.video.fx.fadein import fadein
from moviepy.video.fx.fadeout import fadeout
from moviepy.video.fx.mirror_x import mirror_x
from moviepy.video.fx.mirror_y import mirror_y
from moviepy.video.fx.resize import resize
#etc.

对 moviepy.audio.fx.all

中的 init 执行相同的操作

__init__.py中的实际代码:

__all__ = [name for _, name, _ in pkgutil.iter_modules(
    fx.__path__) if name != "all"]

只需在 [fx.__path__]:

两边加上方括号即可
__all__ = [name for _, name, _ in pkgutil.iter_modules(
    [fx.__path__]) if name != "all"]

我用和 HunterDev 一样的方法解决了这个错误。 这是完整的代码:

Python 3.8.6\Lib\site-packages\moviepy\video\fx\all_初始化_.py

from moviepy.video.fx.accel_decel import accel_decel
from moviepy.video.fx.blackwhite import blackwhite
from moviepy.video.fx.blink import blink
from moviepy.video.fx.colorx import colorx
from moviepy.video.fx.crop import crop
from moviepy.video.fx.even_size import even_size
from moviepy.video.fx.fadein import fadein
from moviepy.video.fx.fadeout import fadeout
from moviepy.video.fx.freeze import freeze
from moviepy.video.fx.freeze_region import freeze_region
from moviepy.video.fx.gamma_corr import gamma_corr
from moviepy.video.fx.headblur import headblur
from moviepy.video.fx.invert_colors import invert_colors
from moviepy.video.fx.loop import loop
from moviepy.video.fx.lum_contrast import lum_contrast
from moviepy.video.fx.make_loopable import make_loopable
from moviepy.video.fx.margin import margin
from moviepy.video.fx.mask_and import mask_and
from moviepy.video.fx.mask_color import mask_color
from moviepy.video.fx.mask_or import mask_or
from moviepy.video.fx.mirror_x import mirror_x
from moviepy.video.fx.mirror_y import mirror_y
from moviepy.video.fx.painting import painting
from moviepy.video.fx.resize import resize
from moviepy.video.fx.rotate import rotate
from moviepy.video.fx.scroll import scroll
from moviepy.video.fx.speedx import speedx
from moviepy.video.fx.supersample import supersample
from moviepy.video.fx.time_mirror import time_mirror
from moviepy.video.fx.time_symmetrize import time_symmetrize

Python 3.8.6\Lib\site-packages\moviepy\audio\fx\all_初始化_.py

from moviepy.audio.fx.audio_fadein import audio_fadein
from moviepy.audio.fx.audio_fadeout import audio_fadeout
from moviepy.audio.fx.audio_left_right import audio_left_right
from moviepy.audio.fx.audio_loop import audio_loop
from moviepy.audio.fx.audio_normalize import audio_normalize
from moviepy.audio.fx.volumex import volumex

更多信息请查看:https://github.com/Zulko/moviepy/issues/591