pyaudio 无法导入 _portaudio

pyaudio could not import _portaudio

正在尝试 运行 python 使用 pyaudio 的应用程序。使用 virtualenv 和安装工作。但是,当 运行ning 时,它找不到 portaudio。但是 _portaudio.so 文件存在。有什么建议吗???

(venv) kidkic@pi-mirror1:~/audio $ jasper/jasper.py 
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
  File "jasper/jasper.py", line 31, in <module>
    from client.mic import Mic
  File "/home/kidkic/audio/jasper/client/mic.py", line 9, in <module>
    import pyaudio
  File "/home/kidkic/audio/venv/local/lib/python2.7/site-packages/pyaudio.py", line 116, in <module>
    import _portaudio as pa
ImportError: /home/kidkic/audio/venv/local/lib/python2.7/site-packages/_portaudio.so: undefined symbol: Pa_GetStreamReadAvailable


# CHECKING THAT THE FILE EXISTS (a binary file)
(venv) kidkic@pi-mirror1:~/audio $ ls venv/local/lib/python2.7/site-packages/_*
venv/local/lib/python2.7/site-packages/_portaudio.so

问题不是找不到库,而是库缺少所需的功能。 (source code)。我 运行 遇到了同样的问题,并且认为问题源于使用错误版本的 portaudio-dev 构建。

您需要做的事情:

  1. 卸载 python-pyaudio 如果你有 sudo apt-get purge --remove python-pyaudio(这是版本 0.2.8)
  2. Download PortAudio 的最新版本 (19)。
  3. 解压并安装 PortAudio
    • ./configure
    • make
    • make install
  4. 获取pyaudio的依赖
    • portaudio19-dev
    • python-all-devpython3-all-dev 对于 Python 3
  5. sudo pip install pyaudio

之后,我就可以使用pyaudio了。

对于 linux 用户,您可能会在安装 portaudio

后得到类似的东西
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------


PortAudio was successfully installed.

On some systems (e.g. Linux) you should run 'ldconfig' now
to make the shared object available.  You may also need to
modify your LD_LIBRARY_PATH environment variable to include
the directory /usr/local/lib

因此,我想按照上述 Wehrdo 回答中的步骤添加以下命令作为第 4 步。

  • sudo ldconfig
  • export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
  • echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/" >> ~/.bashrc

这对我有用

conda install -c anaconda portaudio

pip unistall pyaudio pipwin 安装pyaudio 对于windows台机器

当我用conda安装pyaudio时,出现错误。但是,当我通过 'pip install pyaudio'

使用 pip 安装它时它就消失了

这个包的 conda 源似乎有问题。

问题是目前 python 2.7、3.4、3.5 和 3.6 主要支持 portaudio 和 pyaudio。在您提出问题时,可能不支持 2.7。你总是要检查这个网站:https://pypi.org/project/PyAudio/#files if you want to know which versions of python are compatible. If you want to keep your version of python the same, try this unofficial site for Windows: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio