#871·pydub

PermissionError: [Errno 13] 权限被拒绝:

作者: KuYouRan创建于 2026年2月27日更新于 2026年2月27日

My development environment: python3.11 The code is as follows: ` import tempfile import os from pydub import audio_segment

from pydub.playback import play

Change the temporary directory to the current folder

tempfile.tempdir = os.path.dirname(os.path.abspath(file)) song = audio_segment.AudioSegment.from_file('囍-祖娅纳惜.mp4')

play(song)

print(dir(pydub)) The error is that the file was opened by other code before it was closed, so I modified the code as follows to solve the problem: C:\Users\rkey\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydub\playback.py In the 15th line of the file:
with NamedTemporaryFile("w+b", suffix=".wav") as f: seg.export(f.name, "wav") ` Modify to: ‘ with NamedTemporaryFile("w+b", suffix=".wav") as f: f.close() seg.export(f.name, "wav") ’