[英]How to get a working EXE file using pyinstaller with the sounddevice module in Python
Unfortunately pyinstaller has problem with the sounddevice module. 不幸的是pyinstaller的sounddevice模块有问题。
I wrote the code below, but when I make an EXE file using pyinstaller, the EXE file in the dist folder does not work. 我写了下面的代码,但是当我使用pyinstaller创建EXE文件时,dist文件夹中的EXE文件不起作用。 The making process using pyinstaller finishes successfully but the EXE file does not work. 使用pyinstaller的制作过程成功完成,但是EXE文件不起作用。
The code is: 代码是:
import sounddevice as sd
fs=44100
duration =2 # seconds
print('Start')
myrecording = sd.rec(duration * fs, samplerate=fs, channels=2,dtype='float64')
sd.wait()
print('play')
sd.play(myrecording, fs)
print('end')
Could the problem be that the program exits straight after you do sd.play()
? 问题可能出在您执行sd.play()
之后程序立即退出吗?
Try replacing that line with sd.play(myrecording, fs, blocking=True)
尝试用sd.play(myrecording, fs, blocking=True)
替换该行
Also, sounddevice is not a perfect library, so you need to do a bit of extra tweaking to make it work: 同样,声音设备也不是一个完美的库,因此您需要做一些额外的调整才能使其正常工作:
In your directory where your EXE is located, add a directory called _sounddevice_data
and put this file into that folder (if you are using Python 64-bit) or this one (if you are using Python 32-bit). 在EXE所在的目录中,添加一个名为_sounddevice_data
的目录,然后将此文件放入该文件夹(如果使用的是Python 64位)或该文件夹(如果使用的是32位Python)。
Try running the EXE, it should work! 尝试运行EXE,它应该可以工作!
Hope this helps! 希望这可以帮助!
The selected answer didn't work but helped. 所选答案无效,但有所帮助。
For me, the working solution is to add _sounddevice_data folder where the .exe file is located then making a portaudio-binaries folder in it and finally putting libportaudio64bit.dll in the recently created folder. 对我来说,有效的解决方案是在.exe文件所在的位置添加_sounddevice_data文件夹,然后在其中创建一个portaudio-binaries文件夹,最后将libportaudio64bit.dll放入最近创建的文件夹中。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.