无法导入PyAudio

DMellon

我一直试图让PyAudio安装在我的虚拟环境中,但是未能加载它。

当我尝试通过Pip(Linux Mint)安装它时,得到以下信息:

Collecting pyaudio
  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/doug/Documents/HiFiWave/venv/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-t3OMsn --python-tag cp27
       cwd: /tmp/pip-install-yGZpB4/pyaudio/
  Complete output (16 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
  running build_ext
  building '_portaudio' extension
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/src
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
  src/_portaudiomodule.c:28:10: fatal error: Python.h: No such file or directory
   #include "Python.h"
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyaudio
  Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
    Running setup.py install for pyaudio ... error
    ERROR: Command errored out with exit status 1:
     command: /home/doug/Documents/HiFiWave/venv/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-oTUpfe/install-record.txt --single-version-externally-managed --compile --install-headers /home/doug/Documents/HiFiWave/venv/include/site/python2.7/pyaudio
         cwd: /tmp/pip-install-yGZpB4/pyaudio/
    Complete output (16 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_portaudio' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
    src/_portaudiomodule.c:28:10: fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/doug/Documents/HiFiWave/venv/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yGZpB4/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-oTUpfe/install-record.txt --single-version-externally-managed --compile --install-headers /home/doug/Documents/HiFiWave/venv/include/site/python2.7/pyaudio Check the logs for full command output.

我搜索了Stack Overflow,并遇到了一些类似的问题,但是似乎没有一个起作用。例如,我在这里找到以下解决方案

pip install -e git+http://people.csail.mit.edu/hubert/git/pyaudio.git#egg=pyaudio

它在终端中产生以下故障:

    Obtaining pyaudio from git+http://people.csail.mit.edu/hubert/git/pyaudio.git#egg=pyaudio
  Cloning http://people.csail.mit.edu/hubert/git/pyaudio.git to ./venv/src/pyaudio
  Running command git clone -q http://people.csail.mit.edu/hubert/git/pyaudio.git /home/doug/Documents/HiFiWave/venv/src/pyaudio
Installing collected packages: pyaudio
  Running setup.py develop for pyaudio
    ERROR: Command errored out with exit status 1:
     command: /home/doug/Documents/HiFiWave/venv/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/doug/Documents/HiFiWave/venv/src/pyaudio/setup.py'"'"'; __file__='"'"'/home/doug/Documents/HiFiWave/venv/src/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
         cwd: /home/doug/Documents/HiFiWave/venv/src/pyaudio/
    Complete output (19 lines):
    running develop
    running egg_info
    writing src/PyAudio.egg-info/PKG-INFO
    writing top-level names to src/PyAudio.egg-info/top_level.txt
    writing dependency_links to src/PyAudio.egg-info/dependency_links.txt
    reading manifest file 'src/PyAudio.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'src/PyAudio.egg-info/SOURCES.txt'
    running build_ext
    building '_portaudio' extension
    creating build
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-5Z483E/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
    src/_portaudiomodule.c:28:10: fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/doug/Documents/HiFiWave/venv/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/doug/Documents/HiFiWave/venv/src/pyaudio/setup.py'"'"'; __file__='"'"'/home/doug/Documents/HiFiWave/venv/src/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.

以下内容将正确安装:

sudo apt-get install python-pyaudio python3-pyaudio

当我尝试将其导入文件(VSCode或PyCharm中的文本)时,无法加载。

import pyaudio

在此处输入图片说明

我与导入Pyaudio和导入pyaudio相同

我是否完全错误地安装了此软件,如果可以,我该如何正确完成它?此外,由于最后一种方法已正确安装在我的virtualenv中,我是否将其错误地导入到我的代码中?

谢谢您的宝贵时间,如果有什么我可以补充的内容,请随时提出。

海滩

您可能需要python3-dev在计算机上安装sudo apt install python3-dev

您也可以看一下这个答案向@Paulie大喊大叫

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章