Pyinstaller - 如何隐藏导入moviepy?
Pyinstaller - How to hidden import moviepy?
我想将我的脚本转换为 .exe 并尝试使用 pyinstaller。
问题是没有导入 moviepy。
我将 moviepy 导入为 import moviepy.editor as me
(在 script.py 中)。
所以我尝试了隐藏导入。
命令是:pyinstaller --onefile --hidden-import=moviepy script.py
输出:
3601 INFO: Analyzing hidden import 'moviepy'
3601 ERROR: Hidden import 'moviepy' not found
有人可以帮助我吗?谢谢 :)
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 并将 moviepy
和 imageio-ffmpeg
添加到最终可执行文件中。
您的规范文件应如下所示:(请记住根据您的 Python 目录编辑模块路径)
# -*- 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)
...
最后,生成您的可执行文件:
pyinstaller script.spec
我想将我的脚本转换为 .exe 并尝试使用 pyinstaller。
问题是没有导入 moviepy。
我将 moviepy 导入为 import moviepy.editor as me
(在 script.py 中)。
所以我尝试了隐藏导入。
命令是:pyinstaller --onefile --hidden-import=moviepy script.py
输出:
3601 INFO: Analyzing hidden import 'moviepy'
3601 ERROR: Hidden import 'moviepy' not found
有人可以帮助我吗?谢谢 :)
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 并将 moviepy
和 imageio-ffmpeg
添加到最终可执行文件中。
您的规范文件应如下所示:(请记住根据您的 Python 目录编辑模块路径)
# -*- 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)
...
最后,生成您的可执行文件:
pyinstaller script.spec