首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法将PyAudio导入

无法将PyAudio导入
EN

Stack Overflow用户
提问于 2020-01-20 12:36:15
回答 1查看 191关注 0票数 2

我一直在尝试将PyAudio安装到我的虚拟环境中,但未能将其加载。

当我尝试通过Pip (linux mint)安装它时,我得到了以下结果:

代码语言:javascript
运行
复制
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,发现了一些类似的问题,但似乎没有一个有效。例如,我找到了以下解决方案here

代码语言:javascript
运行
复制
pip install -e git+http://people.csail.mit.edu/hubert/git/pyaudio.git#egg=pyaudio

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

代码语言:javascript
运行
复制
    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.

可以正确安装以下软件:

代码语言:javascript
运行
复制
sudo apt-get install python-pyaudio python3-pyaudio

当我尝试将其导入到文件中时(无论是在VSCode中还是在PyCharm中),它加载失败。

代码语言:javascript
运行
复制
import pyaudio

我用import Pyaudio和import pyaudio得到了相同的结果

我的安装是完全错误的吗?如果是这样,我如何才能正确地完成它呢?另外,自从上一个方法正确安装在我的virtualenv中之后,我是不是错误地将它导入到我的代码中了?

感谢大家抽出时间,如果有什么我可以补充的,请不要犹豫,尽管问。

EN

Stack Overflow用户

回答已采纳

发布于 2020-01-20 12:48:18

您可能需要在您的机器上安装python3-devsudo apt install python3-dev

您还可以查看此答案Shout out to @Paulie

票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59817044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档