简体   繁体   English

pyaudio 无法导入 _portaudio

[英]pyaudio could not import _portaudio

Trying to run python app that uses pyaudio.尝试运行使用 pyaudio 的 python 应用程序。 Using virtualenv and installations are working.使用 virtualenv 和安装工作正常。 However when running it can't find portaudio.但是运行时找不到portaudio。 But the _portaudio.so file exists.但是 _portaudio.so 文件存在。 Any suggestions???有什么建议么???

(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

The issue isn't that it can't find the library, but that the library is missing a function that is needed.问题不是它找不到库,而是库缺少所需的功能。 ( source code ). 源代码)。 I ran into the same problem, and believe the issue stems from building with the wrong version of portaudio-dev .我遇到了同样的问题,并认为问题源于使用错误版本的portaudio-dev构建。

What you need to do:你需要做什么:

  1. Uninstall python-pyaudio with sudo apt-get purge --remove python-pyaudio if you have it (This is version 0.2.8)卸载 python-pyaudio 与sudo apt-get purge --remove python-pyaudio如果你有它(这是版本 0.2.8)
  2. Download the latest version (19) of PortAudio.下载PortAudio 的最新版本 (19)。
  3. Untar and install PortAudio解压并安装 PortAudio
    • ./configure
    • make
    • make install
  4. Get the dependencies for pyaudio获取 pyaudio 的依赖项
    • portaudio19-dev
    • python-all-dev ( python3-all-dev for Python 3 ) python-all-devPython 3 的python3-all-dev
  5. sudo pip install pyaudio

After that, I was able to use pyaudio.之后,我就可以使用pyaudio了。

这对我有用

conda install -c anaconda portaudio

For linux users you may get something like this after you install portaudio对于 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

So, I would like to add the below commands as step number 4, following the steps in above answer by Wehrdo.因此,我想按照 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

when I install pyaudio with conda, the error comes out.当我使用 conda 安装 pyaudio 时,出现错误。 However, it is gone when I just install it with pip by 'pip install pyaudio'但是,当我通过“pip install pyaudio”使用 pip 安装它时它就消失了

It seems like a problem in the conda source of this package.这个包的 conda 源似乎有问题。

The problem is that portaudio and pyaudio are mainly supported for python 2.7, 3.4, 3.5 and 3.6 as of now.问题是目前 python 2.7、3.4、3.5 和 3.6 主要支持 portaudio 和 pyaudio。 At the time you asked the question 2.7 probably wasn't supported.在您提出问题时,可能不支持 2.7。 You always have to check this website: https://pypi.org/project/PyAudio/#files if you want to know which versions of python are compatible.如果你想知道哪些版本的 python 是兼容的,你总是必须检查这个网站: https : //pypi.org/project/PyAudio/#files 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如果你想保持你的 python 版本相同,试试这个非官方的 Windows 站点: https : //www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio

This is what worked for me on M1 MacBook Pro,这就是在 M1 MacBook Pro 上对我有用的方法,

conda install -c anaconda portaudio
pip install pyaudio

Pip unistall pyaudio Pipwin install pyaudio For windows machine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM