NameError: name 'c_int_p' is not defined in pyogg library
I encountered a NameError when trying to use the pyogg library. The error message indicates that c_int_p is not defined. This issue occurs when attempting to use the OpusDecoder from the pyogg library.
OS: macOS (M1) Python version: 3.10.0 pyogg version: [Specify the version you are using] Additional Information: I have installed the necessary dependencies for libopus using Homebrew:
I have also set the DYLD_LIBRARY_PATH environment variable in my .env file:
ibopus.opus_encoder_create.argtypes = [opus_int32, c_int, c_int, c_int_p] NameError: name 'c_int_p' is not defined. Did you mean: 'c_int'?
I ran into the same. no solution?
I found a solution for MacOS M1/M2. The issue occurs because system libraries are located in a different path and opuslib cannot find them.
Solution Steps:
- First, install required libraries using Homebrew:
brew install libogg opus opusfile libopusenc libvorbis flac
brew install opus-tools
- On M1/M2 Macs, Homebrew libraries are located under
/opt/homebrew/lib/. Verify the libraries exist:
ls /opt/homebrew/lib/libopus*
- Set system library paths. Add these lines to your
~/.zshrc(or your shell config file):
export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH
export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH
export PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH
- Apply the changes:
source ~/.zshrc
- Reinstall PyOgg or opuslib:
pip uninstall opuslib
pip install --no-cache-dir opuslib
After following these steps, the library should work correctly. This solution addresses the issue caused by Homebrew installing libraries under /opt/homebrew/lib/ on M1/M2 Macs.