Python 在 virtualenv 中使用 pip 安装 pyaudio
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35708238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing pyaudio with pip in a virtualenv
提问by mertyildiran
I'm trying to install pyaudio with pip:
我正在尝试使用 pip 安装 pyaudio:
pip install pyaudio
In a virtualenv but I'm getting an error:
在 virtualenv 中,但出现错误:
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Entire output:
整个输出:
Collecting pyaudio
Using cached PyAudio-0.2.9.tar.gz
Building wheels for collected packages: pyaudio
Running setup.py bdist_wheel for pyaudio ... error
Complete output from command /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpyR6J73pip-wheel- --python-tag cp27:
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 -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
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
Complete output from command /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-icMIUV-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/include/site/python2.7/pyaudio:
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 -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-icMIUV-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/include/site/python2.7/pyaudio" failed with error code 1 in /tmp/pip-build-GCltlv/pyaudio
What am I doing wrong? I'm new in virtualenvs.
我究竟做错了什么?我是 virtualenvs 的新手。
*I'm able to install other packages. I'm facing with an error only for pyaudio package.
*我可以安装其他软件包。我只面临 pyaudio 包的错误。
By the way I'm in the environment:
顺便说一下,我在环境中:
(ENV) mertyildiran@Corsair:~/Downloads/VirtualEnvironment/vir1/MyProject$
采纳答案by larsks
Some packages require the support of non-Python software, such as shared libraries. These cannotbe installed via pip (they're not Python packages!). You generally install these on the hostusing your host's package manager (apt-getor yumor dnf, etc...), or you use something like Docker to encapsulate both the dependencies and your application.
一些包需要非 Python 软件的支持,例如共享库。这些无法通过PIP进行安装(他们不是Python包!)。您通常使用主机的包管理器(或或等...)将这些安装在主机上,或者使用 Docker 之类的工具来封装依赖项和应用程序。apt-getyumdnf
In your case, pyaudio requires a number of libraries, including at least portaudio. You will need to install the appropriate development packages on your system, as suggested in the comments on your question.
在您的情况下, pyaudio 需要许多库,至少包括portaudio. 您将需要在您的系统上安装适当的开发包,如您问题的评论中所建议的。
回答by Alejandro
This worked for me, I had the same problem:
这对我有用,我遇到了同样的问题:
if you want to install PyAudio inside a virtualenv, install the PortAudio development headers from APT, then PyAudio:
如果要在 virtualenv 中安装 PyAudio,请从 APT 安装 PortAudio 开发头文件,然后安装 PyAudio:
sudo apt-get install portaudio19-dev
pip install --allow-unverified=pyaudio pyaudio
回答by Hitesh Patil
Following steps worked for me :) Please go through and try
以下步骤对我有用:)请通过并尝试
1 sudo apt-get install libasound-dev
2 sudo apt-get install portaudio19-dev
3 pip install pyaudio --user
OR (--user dont work then try python3-pyaudio)
或(--user 不工作,然后尝试 python3-pyaudio)
sudo apt-get install python3-pyaudio
回答by Sumit More
In new Python 3.0 pyaudio can install in windows use following command: pip3 install pyaudio.
在新的 Python 3.0 pyaudio 可以安装在 windows 中使用以下命令:pip3 install pyaudio。
回答by Naveen Joshi
If you want to install pyaudio in virtual environment in windows first you need to download PyAudio-0.2.11-cp37-cp37m-win_amd64.whl this file in [https://www.lfd.uci.edu/~gohlke/pythonlibs/]here and then open command prompt and go to the path where your downloaded file located and type pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
如果你想先在windows虚拟环境下安装pyaudio你需要在[ https://www.lfd.uci.edu/~gohlke/pythonlibs/下载PyAudio-0.2.11-cp37-cp37m-win_amd64.whl这个文件]这里然后打开命令提示符并转到您下载的文件所在的路径并输入 pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl

