关于moviepy打包报错AttributeError: module audio/video.fx.all has no attribute fadein、crop文章的纠错和抄袭
老猿前面有篇文章《moviepy应用pyinstaller打包后执行报错AttributeError: module audio/video.fx.all has no attribute ‘fadein’、crop》,今天居然发现有人原文照抄还获了很多个赞,而老猿的原文居然还没有赞。抄袭文章链接为:https://www.pythonheidong.com/blog/article/314732/。并且这篇文章今天仔细核对了一下,还有错误,在此更正一下。
原文解决办法部分,“如针对audio.fx.all,在Python中手工执行如下代码:”
import pkgutil
import moviepy.video.fx as fx
__all__ = [name for _, name, _ in pkgutil.iter_modules(fx.__path__) if name != "all"]
for name in __all__:
print("from moviepy.video.fx import %s" % (name))
实际上这个地方应该这样处理:
>>> import pkgutil
>>> import moviepy.audio.fx as fx
>>> __all__ = [name for _, name, _ in pkgutil.iter_modules(
fx.__path__) if name != "all"]
>>> for name in __all__:
print("from moviepy.audio.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
>>>
将上面的输出语句拷贝到audio.fx.all的__init__.py,替换被注释的2行代码即可。如movipy1.03的版本中,拷贝到audio.fx.all的__init__.py文件后,该文件内容为如下:
"""
Loads all the fx !
Usage:
import moviepy.audio.fx.all as afx
audio_clip = afx.volume_x(some_clip, .5)
"""
import pkgutil
import moviepy.audio.fx as 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))
#for name in __all__:
# print("from moviepy.audio.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