moviepy是个好东西,但封装起来就不那么友好了,先看报错:
脚本在没有封装的情况下可以正常使用,但是用pyinstaller -F 封装后运行就会直接报错:"module ‘moviepy.audio.fx.all’ has no attribute ‘audio_fadein’“或者” module ‘moviepy.audio.fx.all’ has no attribute ‘audio_fadein’"然后闪退 这两个错是因为moviepy包下子包audio.fx.all、video.fx.all对应的目录moviepy\audio\fx\all、moviepy\video\fx\all下的包文件__init__.py中使用的是一种动态加载模块的模式加载包下的模块的,pyinstaller对这种模式不能处理
解决方法其实很简单: 首先把两个文件的for name in all: exec(“from …%s import %s” % (name, name))注释掉, 改为for name in all: print(“from moviepy.video.fx import %s” % (name))或者for name in all: print(“from moviepy.aideo.fx import %s” % (name)) 手动运行一次,可以得到这么一串代码
from moviepy.audio.fx import audio_fadein
from moviepy.audio.fx import audio_fadeout
from moviepy.audio.fx import audio_left_right
from moviepy.audio.fx import audio_loop
from moviepy.audio.fx import audio_normalize
from moviepy.audio.fx import volumex
将他们粘贴到原来的文件中,替换掉新加的两行代码即可 最终两个__init__.py文件内容如下:
import pkgutil
import moviepy.audio.fx as fx
__all__ = [name for _, name, _ in pkgutil.iter_modules(
fx.__path__) if name != "all"]
from moviepy.audio.fx import audio_fadein
from moviepy.audio.fx import audio_fadeout
from moviepy.audio.fx import audio_left_right
from moviepy.audio.fx import audio_loop
from moviepy.audio.fx import audio_normalize
from moviepy.audio.fx import volumex
import pkgutil
import moviepy.video.fx as fx
__all__ = [name for _, name, _ in pkgutil.iter_modules(
fx.__path__) if name != "all"]
from moviepy.video.fx import accel_decel
from moviepy.video.fx import blackwhite
from moviepy.video.fx import blink
from moviepy.video.fx import colorx
from moviepy.video.fx import crop
from moviepy.video.fx import even_size
from moviepy.video.fx import fadein
from moviepy.video.fx import fadeout
from moviepy.video.fx import freeze
from moviepy.video.fx import freeze_region
from moviepy.video.fx import gamma_corr
from moviepy.video.fx import headblur
from moviepy.video.fx import invert_colors
from moviepy.video.fx import loop
from moviepy.video.fx import lum_contrast
from moviepy.video.fx import make_loopable
from moviepy.video.fx import margin
from moviepy.video.fx import mask_and
from moviepy.video.fx import mask_color
from moviepy.video.fx import mask_or
from moviepy.video.fx import mirror_x
from moviepy.video.fx import mirror_y
from moviepy.video.fx import painting
from moviepy.video.fx import resize
from moviepy.video.fx import rotate
from moviepy.video.fx import scroll
from moviepy.video.fx import speedx
from moviepy.video.fx import supersample
from moviepy.video.fx import time_mirror
from moviepy.video.fx import time_symmetrize
|