我已经使用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
,但错误完全相同。
答案 0 :(得分:3)
我在使用pyinstaller构建.exe文件时遇到了同样的错误。
但是,我将import语句更改为from moviepy.video.io.VideoFileClip import VideoFileClip
它起作用了。
答案 1 :(得分:0)
对于遇到相同问题的每个人,我都可以通过修改选定的 init 文件来解决它,如下图所示:
其中有一段代码可以导入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进行相同操作
答案 2 :(得分: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"]
答案 3 :(得分: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