“ImportError: Nenhum módulo chamado pyaudio” apesar do python-pyaudio instalado

2

Estou tentando executar um programa em Python que usa o pyaudio:

  1. Eu baixei o programa ( do Github porque o .deb é muito antigo)
  2. eu instalo python-pyaudio
  3. eu corro o programa
  4. O programa diz ImportError: No module named 'pyaudio'

O que estou fazendo de errado?

$ sudo apt-get install python-pyaudio
[sudo] password for nico: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  python-pyaudio-doc
The following NEW packages will be installed:
  python-pyaudio
0 upgraded, 1 newly installed, 0 to remove and 49 not upgraded.
Need to get 0 B/24.1 kB of archives.
After this operation, 109 kB of additional disk space will be used.
Selecting previously unselected package python-pyaudio.
(Reading database ... 336001 files and directories currently installed.)
Preparing to unpack .../python-pyaudio_0.2.8-1build2_amd64.deb ...
Unpacking python-pyaudio (0.2.8-1build2) ...
Setting up python-pyaudio (0.2.8-1build2) ...

$ ./runanki 
Traceback (most recent call last):
  File "./runanki", line 3, in <module>
    import aqt
  File "/home/nico/src/anki/aqt/__init__.py", line 4, in <module>
    from anki import version as _version
  File "/home/nico/src/anki/anki/__init__.py", line 13, in <module>
    from anki.storage import Collection
  File "/home/nico/src/anki/anki/storage.py", line 12, in <module>
    from anki.collection import _Collection
  File "/home/nico/src/anki/anki/collection.py", line 26, in <module>
    from anki.sound import stripSounds
  File "/home/nico/src/anki/anki/sound.py", line 207, in <module>
    import pyaudio
ImportError: No module named 'pyaudio'

Ambiente:

$ which python
/usr/bin/python
$ python --version
Python 2.7.11+
    
por Nicolas Raoul 14.07.2016 / 09:47

1 resposta

3

A causa do problema é que o shebang do script runanki no link indica explicitamente Python 3, então ./runanki invoca o interpretador do Python 3, mas você instalou o pyaudio para o Python 2. Como resultado, o Python 3 não é capaz de encontrar pyaudio e, portanto, gera um ImportError . A solução mais fácil aqui é instalar as ligações do Python 3 para pyaudio executando:

sudo apt update && sudo apt install python3-pyaudio
    
por edwinksl 14.07.2016 / 10:13