gpt4 book ai didi

python - py2exe和moviepy属性错误

转载 作者:太空宇宙 更新时间:2023-11-03 17:00:57 24 4
gpt4 key购买 nike

我使用 py2exe 生成应用程序时没有出现任何问题。但是,当我执行 .exe 时,它​​会抛出下一个回溯:

Traceback (most recent call last):
File "editor.py", line 25, in <module>
File "moviepy\editor.pyo", line 72, in <module>

File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'audio_fadein'

我以前使用 py2exe 取得了成功的结果,但现在我使用 moviepy 我无法使其工作。这是我的setup.py,执行python setup.py py2exe时没有错误:

from distutils.core import setup
from py2exe.build_exe import py2exe
import os
from distutils.filelist import findall
import matplotlib

datafiles = ['logo.png', 'Lower Brand.png', "icon.ico"]

matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = []

for f in matplotlibdata:
dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
matplotlibdata_files.append((os.path.split(dirname)[0], [f]))

mpl = matplotlib.get_py2exe_datafiles()
datafiles.extend(mpl)


setup(
name='VTE',
description="Video Test Editor",
version="1.0",
author="David Rodriguez",


data_files=datafiles,

console=[
{
'script':'videoeditor.py',
'icon_resources': [(1, r"icon.ico")]
}
],
options={ 'py2exe': {
'skip_archive':True,
'includes': ['sip', 'moviepy'],
'excludes': ['_gtkagg', '_tkagg', '_ssl'],
'optimize': 2,
'unbuffered': True
}
},
)

最佳答案

moviepy 使用 exec 进行大量动态导入,这会导致 py2exe 出错。我通过手动将整个 moviepy 模块复制到构建文件夹中解决了问题:

import moviepy
from pathlib import Path
import shutil

moviepy_path= Path(moviepy.__file__).parent
target_path= Path(sys.argv[0]).parent / 'build' / 'exe.win32-3.4' / 'moviepy'
shutil.rmtree(str(target_path))
shutil.copytree(str(moviepy_path), str(target_path))

关于python - py2exe和moviepy属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34991612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com