Ubuntu16.04下如何为Python3.6.5安装PyAudio模块?
Hey there! I get it—apt installs can be tricky when you’ve got multiple Python versions floating around. Let’s get PyAudio working with your custom Python 3.6.5 setup step by step:
Step 1: Install System Dependencies First
PyAudio relies on the PortAudio library, so we need to install its development files first (this avoids those frustrating compilation errors when using pip):
sudo apt-get update && sudo apt-get install portaudio19-dev
Step 2: Use Python 3.6’s Specific Pip to Install PyAudio
The python3-pyaudio package from apt is tied to Ubuntu 16.04’s default Python 3.5, which is why it doesn’t show up in your 3.6.5 environment. Instead, use the pip linked directly to your Python 3.6 installation:
- First, make sure you have pip for Python 3.6. If running
which pip3.6returns nothing, install it with:python3.6 -m ensurepip --upgrade - Now install PyAudio using this version-specific pip:
If you hit permission issues (like being blocked from writing to system directories), add thepip3.6 install pyaudio--userflag to install it only for your account:pip3.6 install --user pyaudio
Step 3: Verify the Installation
To confirm everything works, run this quick test command:
python3.6 -c "import pyaudio; print('PyAudio version:', pyaudio.__version__)"
If you see the version number printed without errors, you’re good to go!
Why This Works
Ubuntu’s apt packages are built to target the system’s default Python versions. Since you installed Python 3.6.5 manually, it’s a separate environment that doesn’t recognize packages installed via apt-get install python3-pyaudio. Using the version-specific pip ensures the package gets installed directly into your 3.6.5 site-packages directory.
内容的提问来源于stack exchange,提问作者RishiC

