无法从 PyAudio 导入 _PaDeviceInfo

发布于 2025-01-14 13:47:30 字数 460 浏览 4 评论 0原文

使用 pyaudio 编写一个简单的应用程序,并尝试学习 python 的打字提示系统。我无法使用 _PaDeviceInfo 类型。尽管它在 VSCode 中自动完成,但当我运行代码时,它会出错,显示“无法从 'pyaudio'(..lib\site-packages\pyaudio.py) 导入名称 '_PaDeviceInfo'”。

我认为这个别名可能来自 .pyi 文件?我将 VSCode 与 Pylance 和 Pyright 一起使用。我已经在这个虚拟环境中安装了 pyaudio 和 types-pyaudio 。谢谢。

from pyaudio import PyAudio, Stream, _PaDeviceInfo

p = pyaudio.PyAudio()
device_info  : _PaDeviceInfo = p.get_device_info_by_index(device_id)
        

Writing a simple application using pyaudio, and trying to learn python's typing hint system. I can't use the _PaDeviceInfo type. Even though it autocompletes in VSCode, it errors out when I run the code, saying "cannot import name '_PaDeviceInfo' from 'pyaudio'(..lib\site-packages\pyaudio.py)".

I think this alias could be coming from the .pyi file? I'm using VSCode with Pylance and Pyright. I've installed pyaudio and types-pyaudio in this virtual environment. Thanks.

from pyaudio import PyAudio, Stream, _PaDeviceInfo

p = pyaudio.PyAudio()
device_info  : _PaDeviceInfo = p.get_device_info_by_index(device_id)
        

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Pyaudio只包含两个类:PyAdudio和Stream。

from pyaudio import PyAudio, Stream, _PaDeviceInfo

删除最后一个“,_PaDeviceInfo”。它不属于这里。
以下是 pyaudio 的 API:https://people.csail。 mit.edu/hubert/pyaudio/docs/#pyaudio.PyAudio

Pyaudio contains only two classes:PyAdudio and Stream.

from pyaudio import PyAudio, Stream, _PaDeviceInfo

Delete the last ", _PaDeviceInfo".It doesn't belong here.
Here is the API for pyaudio:https://people.csail.mit.edu/hubert/pyaudio/docs/#pyaudio.PyAudio

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文