我在Windows 10和notepad ++上使用Winpython,并希望运行以下Python代码:
import wave, struct, math
sampleRate = 44100.0 # hertz
duration = 1.0 # seconds
frequency = 440.0 # hertz
wavef = wave.open('sound.wav','w')
wavef.setnchannels(1) # mono
wavef.setsampwidth(2)
wavef.setframerate(sampleRate)
for i in range(int(duration * sampleRate)):
value = int(32767.0*math.cos(frequency*math.pi*float(i)/float(sampleRate)))
data = struct.pack('<h', value)
wavef.writeframesraw( data )
wavef.writeframes('')
wavef.close()
但是我收到以下错误:
Traceback (most recent call last):
File "C:\Users\HP\Desktop\WinPython-64bit-2.7.10.3\robin\sound\wav_00.py", line 7, in <module>
wavef = wave.open('sound.wav','w')
File "C:\Users\HP\Desktop\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\wave.py", line 513, in open
return Wave_write(f)
File "C:\Users\HP\Desktop\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\wave.py", line 308, in __init__
f = __builtin__.open(f, 'wb')
IOError: [Errno 13] Permission denied: 'sound.wav'
我正在使用C:\Users\HP\Desktop\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\python.exe -i "$(FULL_CURRENT_PATH)"
当我使用我注册的Python安装在Winpython文件夹之外运行脚本时,它工作正常,但我想使用Winpython版本中安装的软件包,所以这个解决方案不够
请有人解释如何使这项工作?
答案 0 :(得分:0)
尝试以管理员身份运行。
如果从Windows命令提示符运行:
右键单击Windows按钮
选择&#34;命令提示符(管理员)&#34;
执行脚本
希望这有帮助