How to properly install PyAudio for the latest version of Python? - python

I was using speech_recognition with the latest version of Python (3.9). And for some reason, pip did not (still does not) allow me to install pyaudio.
sample of the error message:
_portaudiomodule.c
c:\program files\python39\include\pyconfig.h(117): warning C4005: 'MS_WIN64': macro redefinition
src/_portaudiomodule.c: note: see previous definition of 'MS_WIN64'
src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
----------------------------------------
It has been meaningless for me to look for what portaudio.h does.
Here is the solution. I hope you don't waste your time like I did.

The reason is pip gets the packages from PyPi. And PyPi does not have PyAudio package that supports Python 3.9. This is why, it is useless to try and install pyaudio with pip install pyaudio.
What you should do, instead, is you go to Unofficial Windows Binaries for Python Extension Packages page and download the pip wheel:
last step is to run
pip install [insert pyaudio wheel directory]\pyAudio-0.2.11-cp39-cp39-win_amd64.whl
You should be alright with this.
By the way, this trick works with other packages that you want to run with the latest python version.

Related

Pip install results in this error " cl.exe' failed with exit code 2 "

I've read all of the other questions on this error and frustratingly enough, none give a solution that works.
If I run pip install sentencepiece in the cmd line, it gives me the following output.
src/sentencepiece/sentencepiece_wrap.cxx(2809): fatal error C1083: Cannot open include file: 'sentencepiece_processor.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
I'm running python 3.10.1 and pip 22.0.3 .
*I have the following Microsoft Visual C++ programs on my windows machine,which I've just done a fresh install of as it was complaining of not having a particular C++ program.
MS VC++
I've even added the .exe file to my PATH variables but still I get the same error.
Am I missing a particular Microsoft program on my pc?
I haven't seen this problem in Windows, but for Linux, I would normally reinstall Python after installing the dependencies (such as the MSVC thing). In that case this is especially helpful because I'm often rebuilding (compiling and other related steps) Python/Pip.
Could also just be an error specific to the module and Python version combo you're trying.
From a discussion in the comments:
I have the pyenv-win version manager, so I was able to create venvs and test this for you. With Python 3.10.2, it fails; with Python 3.8.10, it's successful. So, yes, reinstalling does seem to be worthy of your time.
With python3.10
On Windows: First, install vcpkg and install sentencepiece:x64-windows-static
copy the header and lib files from vcpkg/installed/x64-windows-static/include and lib to
C:/Program Files/python310/build/root/include and lib
This should work as the setup.py install expects the library in a ..\build\root\lib directory.
As the C:\Program Files\python310\lib is in the /LIBPATH, the resulting ..\build\root\lib will point to the sentencepiece.lib
If still encounting errors, then set the INCLUDE and LIB environment variables so that the cl.exe , which is called from pip install sentencetransformers finds them.
People having windows+python 3.10 env, here are exact steps to install it via vcpkg.
Other instructions are covered in zweistein's answer.
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install sentencepiece:x64-windows-static

error in installing a module or package or something in python

I am trying to install pyaudio module in my terminal for python, and I got this error.
rc/_portaudiomodule.c(29): fatal error C1083: Cannot open include
file: 'portaudio.h': No such file or directory
error: command 'C:\Program Files\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\bin\HostX86\x86\cl.exe'
failed with exit status 2
Help me please
If you are targeting native Win32 Python, you will need either MinGW (via Cygwin) or Microsoft Visual Studio
pyaudio compilation docs
Try this
pip install pipwin
pipwin install pyaudio

Cannot Install PyAudio, portaudiomodule error

Currently trying to install PyAudio on my Surface Pro 7, and am getting this error code when I try to use the prompt pip install PyAudio to install it:
ERROR: Command errored out with exit status 1:
src/_portaudiomodule.c: note: see previous definition of 'MS_WIN64'
src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
Can someone help explain why this won't work, please? Thanks!
Download a wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/ and install via pip install wheelfile.whl. Check your python version before downloading.
This issue means that the PyAudio library has a script with an include statement for the portaudio header file. Include statements in C and similar languages are like Import statements in Python. Because the file doesn't exist, the library can't run.
If PyAudio is installed via pip, PortAudio has to be downloaded separately. Here is the official website with instructions to download.
An alternative would be to use Anaconda to install packages for python. Anaconda will automatically install portaudio, or provide a reason why it can't, in which case, you will have to follow the steps on the website linked earlier.
Also, see this SO Question.

Installing pyCLD3 on Windows 10

I'm trying to install pyCLD3 on Windows 10 (python 3.8.5):
pip install pycld3 on Windows does not work (as expected, it's mentioned in the README file on their Github).
However, the instructions how to install it from Source are not clear, it only states that I need some prerequisites and gives an unclear reference on how to install one of them (Protobuf), but not the others and not how to proceed to install pyClD3 itself.
I managed to install Protoc using Chocolatey consulting this post, however, I'm not sure if that's how I should have done it and how to proceed next, i.e. what are the Protobuf development headers and where to find libprotoc library - is it the same thing as Protobuf/protoc?
As for g++, I have installed MinGW from here, but also confused what to do with it next.
Here is a snippet of what I get when I try to install pyCLD3 using pip:
Building wheels for collected packages: pycld3
Building wheel for pycld3 (setup.py) ... error
ERROR: Command errored out with exit status 1:
<...>
Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /EHsc /Tpcld3/pycld3.cpp /Fobuild\temp.win-amd64-3.8\Release\cld3/pycld3.obj -std=c++11
cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
pycld3.cpp
C:\Users\me\AppData\Local\Temp\pip-install-1lgq4b5o\pycld3_11fb5b01d9d44711b4031f733ec7f6cc\src\cld_3/protos/feature_extractor.pb.h(10): fatal error C1083: Cannot open include file: 'google/protobuf/port_def.inc': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Failed building wheel for pycld3
You may try Msys2. I managed to compile pycld3 in Windows 10 with Python3.7.
In Windows 10's cmd
download pycld3-0.20.tar.gz from https://pypi.org/project/pycld3/#files, untar it and cd to that directory
creatae a Py3.7 virtual environ (py -3.7 -m venv venv). (I dont know whether other Python versions work or not.)
Msys2
install msys2 https://www.msys2.org/
start msys2 (c:\msys64\msys2.exe)
update msys2: do a few pacman -Syuu as necessary
install the toolchain (pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-make)
install protoc (pacman -S mingw-w64-x86_64-protobuf, protoc installed by choco didnt work in my experiment but this protoc works)
setup PATH (export PATH=$PATH:/mingw64/bin/)
insert a #include <math.h> line before line 6 of Python.h (e.g C:\Python\Python37\include\Python.h in my case). This fixed the _hypot related errors.
compile and install (go to the directory above, e.g. cd /c/Users/xyz/Downloads/pycld3-0.20/pycld3-0.20 and execute ./venv/Scripts/python.exe setup.py build)
I managed to successfully build pycld3 but was unable to isntall -- got some ValueError: ZIP does not support timestamps before 1980 error when I tried venv/Scripts/python setup.py install.
Please accept my answer if it fixes your 'google/protobuf/port_def.inc': No such file or directory problem:).

'sqlite3.h': No such file or directory

I am attempting to install the pysqlite module for Python 2.7 on my Windows 10 computer. I issued the following command:
pip install pysqlite
The installation ran as usual until it hit an error:
c:\users\xaresys\appdata\local\temp\pip-build-xleoab\pysqlite\src\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory
error: command 'C:\Users\xaresys\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe' failed with exit status 2
I also tried to install a similar module, pysqlcipher, which hit the same error. Do I need to install anything before installing this? Thanks.
Looks like you are missing Visual C++ binaries which are required to install some packages. Follow instructions here: https://github.com/develersrl/gccwinbinaries

Categories