5

我已经使用 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但完全相同的错误。

4

4 回答 4

7

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

于 2017-09-06T04:46:19.853 回答
2

对于有相同问题的每个人,我通过修改下 图所示的选定初始化文件来解决它:

文件位置

在其中有一段代码可以导入 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 执行相同操作

于 2018-09-05T14:58:25.220 回答
0

中的实际代码__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"]
于 2019-09-10T06:19:12.640 回答
0

我以与 HunterDev 相同的方式解决了错误。这是完整的代码:

Python 3.8.6\Lib\site-packages\moviepy\video\fx\ all_init _.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_init _.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

于 2020-11-29T12:06:25.160 回答