问题1:pyinstaller不认exec这种方法
在python环境\Lib\site-packages\moviepy\audio\fx\all的__init__.py文件下:
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__:
exec("from ..%s import %s" % (name, name))
打印出需要导入的库
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 ..%s import %s" % (name, name))
exec("from ..%s import %s" % (name, name))
注释exec内容,手动导入打印出需求库(video\fx\all的__init__.py同样配置)
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 ..%s import %s" % (name, name))
# exec("from ..%s import %s" % (name, name))
from ..accel_decel import accel_decel
from ..blackwhite import blackwhite
from ..blink import blink
from ..colorx import colorx
from ..crop import crop
from ..even_size import even_size
from ..fadein import fadein
from ..fadeout import fadeout
from ..freeze import freeze
from ..freeze_region import freeze_region
from ..gamma_corr import gamma_corr
from ..headblur import headblur
from ..invert_colors import invert_colors
from ..loop import loop
from ..lum_contrast import lum_contrast
from ..make_loopable import make_loopable
from ..margin import margin
from ..mask_and import mask_and
from ..mask_color import mask_color
from ..mask_or import mask_or
from ..mirror_x import mirror_x
from ..mirror_y import mirror_y
from ..painting import painting
from ..resize import resize
from ..rotate import rotate
from ..scroll import scroll
from ..speedx import speedx
from ..supersample import supersample
from ..time_mirror import time_mirror
from ..time_symmetrize import time_symmetrize
问题2:打包成exe,运行报错(下图)
FileNotFoundError:Package has no location <module 'imageio_ffmpeg.biaries'(namespace)>
工程目录下新建hook-imageio_ffmpeg.py文件
from PyInstaller.utils.hooks import collect_all
datas, binaries, hiddenimports = collect_all('imageio_ffmpeg')
重新打包代码
pyinstaller --onefile --additional-hooks-dir=. you_script.py
附:numpy打包exe问题
解:部分python版本报错,小编使用python==3.8,各位可以参考一下