Search code examples
pythonpython-3.xexepyinstallermoviepy

Pyinstaller - How to hidden import moviepy?


I want to convert my script to an .exe and have tried it with pyinstaller. The problem is that moviepy is not imported. I imported moviepy as import moviepy.editor as me (in script.py).

So i tried the hidden import. The command was: pyinstaller --onefile --hidden-import=moviepy script.py

output:

3601 INFO: Analyzing hidden import 'moviepy'  
3601 ERROR: Hidden import 'moviepy' not found

Could someone help me? Thanks :)


Solution

  • hidden-imports will only add the module itself and not its dependencies. It seems that PyInstaller can't handle moviepy automatically, and it would lack some dependencies like imageio-ffmpeg, so you can use Tree class and add both moviepy and imageio-ffmpeg to final executable.

    Your spec file should look like this: (Remember to edit the module path based on your Python directory)

    # -*- mode: python -*-
    
    block_cipher = None
    
    
    a = Analysis(
        ...
    )
    a.datas += Tree("./env/Lib/site-packages/moviepy", prefix='moviepy')
    a.datas += Tree("./env/Lib/site-packages/imageio_ffmpeg/", prefix='imageio_ffmpeg')
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    ...
    

    Finally, generate your executable with:

    pyinstaller script.spec