I am new to python and pip, but wanted to tinker around with sound synthesis via python. So I tried to install pyaudio like it is described on the pyaudio website. Installing portaudio via homebrew was successful
/usr/local/Cellar/portaudio/19.6.0: 33 files, 452KB
When I ran the install command for pyaudio I got this:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pyaudio.pyc'
Consider using the `--user` option or check the permissions.
So I tried this:
pip install --user pyaudio
And got this:
Collecting pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.11
Now, when i run this script (which i found here) I get the following error message
import math #import needed modules
import pyaudio #sudo apt-get install python-pyaudio
PyAudio = pyaudio.PyAudio #initialize pyaudio
#See https://en.wikipedia.org/wiki/Bit_rate#Audio
BITRATE = 16000 #number of frames per second/frameset.
FREQUENCY = 500 #Hz, waves per second, 261.63=C4-note.
LENGTH = 1 #seconds to play sound
if FREQUENCY > BITRATE:
BITRATE = FREQUENCY+100
NUMBEROFFRAMES = int(BITRATE * LENGTH)
RESTFRAMES = NUMBEROFFRAMES % BITRATE
WAVEDATA = ''
#generating wawes
for x in xrange(NUMBEROFFRAMES):
WAVEDATA = WAVEDATA+chr(int(math.sin(x/((BITRATE/FREQUENCY)/math.pi))*127+128))
for x in xrange(RESTFRAMES):
WAVEDATA = WAVEDATA+chr(128)
p = PyAudio()
stream = p.open(format = p.get_format_from_width(1),
channels = 1,
rate = BITRATE,
output = True)
stream.write(WAVEDATA)
stream.stop_stream()
stream.close()
p.terminate()
Error message
/Users/Mogli/PycharmProjects/aCoherentJourney/venv/bin/python /Users/Mogli/PycharmProjects/aCoherentJourney/test.py
Traceback (most recent call last):
File "/Users/Mogli/PycharmProjects/aCoherentJourney/test.py", line 2, in <module>
import pyaudio #sudo apt-get install python-pyaudio
ModuleNotFoundError: No module named 'pyaudio'
Process finished with exit code 1
I've been googling this problem for days now and have similar problems with other modules. My guess is, that it might have to do something with different python versions being installed on my system. So i also tried installing it via
pip3 install --user pyaudio
Python Versions
python --version
Python 2.7.10
python3 --version
Python 3.6.4
Python3 was installed via homebrew. brew info python
returns:
python: stable 3.7.1 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.0 (4,781 files, 102MB)
Poured from bottle on 2018-11-06 at 21:04:42
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config ✘
Required: gdbm ✔, openssl ✔, readline ✔, sqlite ✘, xz ✔
Optional: tcl-tk ✘
==> Options
--with-tcl-tk
Use Homebrew's Tk instead of macOS Tk (has optional Cocoa and threads support)
--HEAD
Install HEAD version
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python@2
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 282,353 (30 days), 711,193 (90 days), 2,944,083 (365 days)
install_on_request: 172,678 (30 days), 469,977 (90 days), 1,781,137 (365 days)
build_error: 0 (30 days)
I don't know what to try next. Any help would be appreciated :)