Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

python - pyaudio could not import _portaudio

Trying to run python app that uses pyaudio. Using virtualenv and installations are working. However when running it can't find portaudio. But the _portaudio.so file exists. 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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)
  2. Download the latest version (19) of PortAudio.
  3. Untar and install PortAudio
    • ./configure
    • make
    • make install
  4. Get the dependencies for pyaudio
    • portaudio19-dev
    • python-all-dev (python3-all-dev for Python 3)
  5. sudo pip install pyaudio

After that, I was able to use pyaudio.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...