syntax error and module error

#8 · open · 7 comments

View on GitHub ↗

SamMuel112

Hello, I am trying to use this code on a raspberry pito make a live oscilloscope (as a prototype) for my modular synthesizer. I have 2 main errors. one says: File "/home/pi/Desktop/Waveformviewer1.py", line 13 %matplotlib tk ^ SyntaxError: invalid syntax I tried bypassing it by commenting it with a #. but it brought up: File "/home/pi/Desktop/Waveformviewer1.py", line 5, in <module> import pyaduio ImportError: No module named 'pyaudio' To resolve this I have tried running install commands in the terminal updates upgrades all that sort of back-end stuff but it's still not working. please help

Comments

rudrathegreat

One thing is that instead of using `%matplotlib tk` use - ```Python import matplotlib matplotlib.use('TkAgg') ``` But remember that in order to have the TkAgg backend, you must have `python tk`. Secondly, pyaudio must be installed. In order to check if that has been installed, try importing it in the Python Shell. If the module has not been found, then that means that it has not been properly installed. ```Python import pyaudio ``` In order to install pyaudio, you need to install portaudio. After that, you can safely install pyaudio with no errors ```Bash sudo pip install PyAudio ``` Another thing to notify here is that portaudio is programmed in C, so you need to build it using something like Microsoft Visual Studio. I hope I helped you with your issue! P.S - I am not an artificial intelligent program or robot!

SamMuel112

Thank you so much for your reply!!!!. Ill try that tomorrow afternoon as its almost midnight here now. One question. Will port audio (as you mention it being programmed in c) actually work on rasberry pi? As i wont be able to run MVS on the Pi? Will it be a problem? If so is there an alternative?? Sam

rudrathegreat

Yes it should, I have done this process on a Linux laptop. All you need to do is configure and build portaudio before installing pyaudio. ```Bash ./configure && make ``` Just remember that PyAudio is sort of like an interface between PortAudio and Python! Another thing is that if you are having doubts that you do not have python tk, you can check by importing tkinter - ```Python import tkinter as tk ``` If it gives an error, then you have to install it - ```Bash sudo apt-get install python-tk sudio apt-get install python3-tk ``` Then try importing it again! :smile:

rudrathegreat

Another thing to note is that when you have `python tk` and you have the TkAgg backend, then you don't exactly have to do this - ```Python matplotlib.use('TkAgg') ``` Because when you have the TkAgg backend, that is your default backend.

SamMuel112

okay, so I did everything you said. I think we got rid of the matplotlib problems but we still have issues with the pyaudio modules not found. the only thing you said to do that I 'couldn't' do was the ./confige && make where was that suppose to go?? also could not specifically install portaudio. not sure if I was supposed to be able to but yeah ive got photos of my responses if it helps.

rudrathegreat

The part where you have to build portaudio is actually from the documentation - http://www.portaudio.com Again, the reason why pyaudio was not installed was because it couldn't technically find PortAudio. See, in order for PortAudio to be recognised, it needs to be built. Installation for PyAudio is also mentioned here, however it doesn't mention how to install PortAudio, make it recognisable for PyAudio, which is why you need to go to the PortAudio documentation - https://people.csail.mit.edu/hubert/pyaudio/ I hope that helped with the PyAudio problem!

rudrathegreat

This is what the PyAudio documentation mentions - > To build PyAudio from source, you will also need to build PortAudio v19. I have also found a reference to this issue - https://stackoverflow.com/questions/33513522/when-installing-pyaudio-pip-cannot-find-portaudio-h-in-usr-local-include I hope that helped with the issue!