使用sx_Freeze编译movie.py遇'NoneType'无write属性错误求助
sx_Freeze编译MoviePy脚本后出现'NoneType'无'write'属性错误
我编写的cut_out_a_movie_piece函数在本地编辑器运行正常,但使用sx_Freeze编译为可执行文件后,抛出错误:'NoneType' object has no attribute 'write',已定位错误出现在第338行的clip1.write_videofile(new_full_path)代码处。
另外测试发现,用PyInstaller编译该脚本时完全没有问题,因此可以确定错误与sx_Freeze的编译机制相关。
函数代码
def cut_out_a_movie_piece(movie_path, start1, stop1, start2=None, stop2=None): from moviepy.editor import concatenate_videoclips, VideoFileClip try: movie_name = pathlib.Path(movie_path).stem ext = pathlib.Path(movie_path).suffix folder = pathlib.Path(movie_path).parent new_full_path = os.path.join(folder,movie_name + ".mp4") clip1 = VideoFileClip(movie_path).subclip(start1,stop1) if start2 and stop2: clip2 = VideoFileClip(movie_path).subclip(start2,stop2) combined = concatenate_videoclips([clip1,clip2]) combined.write_videofile(new_full_path) else: clip1.write_videofile(new_full_path) # this is the line 338, producing the error shutil.move(new_full_path,r'D:\_MUSIC\Filmi_Musica') except Exception as e: with open('Run_Scripts_ERROS.LOG', "a") as f: f.write(str(e)) f.write('\n') f.write(f'line # ----> {e.__traceback__.tb_lineno}') f.write('\n') f.write(f'that was in cut_out_a_movie_piece')
异常输出
'NoneType' object has no attribute 'write' line # ----> 338
内容的提问来源于stack exchange,提问作者LetzerWille
相关产品推荐
相关产品推荐

