Why am I getting a runtime error / key error "no device found for" empty device address? - linux

Why am I getting the following error message when executing uhd_fft GNU Radio script:
/opt/gnuradio-3.7.1git/bin$ uhd_fft
linux; GNU C++ version 4.6.3; Boost_104601; UHD_003.005.003-123-g1c391767
Traceback (most recent call last):
File "/opt/gnuradio-3.7.1git/bin/uhd_fft", line 341, in <module>
main ()
File "/opt/gnuradio-3.7.1git/bin/uhd_fft", line 337, in main
app = stdgui2.stdapp(app_top_block, "UHD FFT", nstatus=1)
File "/opt/gnuradio-3.7.1git/lib/python2.7/dist-packages/gnuradio/wxgui/stdgui2.py", line 38, in __init__
wx.App.__init__ (self, redirect=False)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7981, in __init__
self._BootstrapApp()
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7555, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "/opt/gnuradio-3.7.1git/lib/python2.7/dist-packages/gnuradio/wxgui/stdgui2.py", line 42, in OnInit
self._max_noutput_items)
File "/opt/gnuradio-3.7.1git/lib/python2.7/dist-packages/gnuradio/wxgui/stdgui2.py", line 64, in __init__
self.panel = stdpanel (self, self, top_block_maker, max_nouts)
File "/opt/gnuradio-3.7.1git/lib/python2.7/dist-packages/gnuradio/wxgui/stdgui2.py", line 86, in __init__
self.top_block = top_block_maker (frame, self, vbox, sys.argv)
File "/opt/gnuradio-3.7.1git/bin/uhd_fft", line 91, in __init__
otw_format=options.wire_format, args=options.stream_args))
File "/opt/gnuradio-3.7.1git/lib/python2.7/dist-packages/gnuradio/uhd/__init__.py", line 121, in constructor_interceptor
return old_constructor(*args)
File "/opt/gnuradio-3.7.1git/lib/python2.7/dist-packages/gnuradio/uhd/uhd_swig.py", line 1700, in make
return _uhd_swig.usrp_source_make(*args)
RuntimeError: LookupError: KeyError: No devices found for ----->
Empty Device Address
I'm using BladeRF hardware and followed these instructions.
I have gone through the recommendations listed here but UHD_FFT still can't seem to find the BladeRF even though
ls -lrt /dev | grep blade
crw------- 1 root root 180, 0 Aug 11 14:04 bladerf0
Why would my device not be found by UHD_FFT even though linux is aware of its existence ?

It looks like your BladeRF is only accessible by the root user. To fix this make a udev rule file (I know the write up you followed earlier had you do something similar, but bear with me). This will allow your regular user account to access it. You can start in the shell by typing:
$ sudo nano /etc/udev/rules.d/15-bladerf
This should make a new file and open the nano editor. Here you will place the following:
SUBSYSTEM=="usb", SYSFS{idVendor}=="1d50", SYSFS{idProduct}=="6066", MODE="0666"
Afterwards, reset the udev rules service by executing:
$ sudo /etc/init.d/udev restart
NOTE: This commands should work on any Debian-based OS (Debian, Ubuntu, Linux Mint,...)
CREDIT: The udev rules were found here http://pastebin.com/Mgb90L1x

Related

python script in cron not reading a CSV unless it creates the CSV itself

I have the following script. It works when I run it in command line, and it works when I run it in cron.
The variable 'apath' is the absolute path of the file.
cat=['a','a','a','a','a','b','b','b','b','b']
val=[1,2,3,4,5,6,7,8,9,10]
columns=['cat','val']
data=[cat,val]
dict={key:value for key,value in zip(columns,data)}
statedata_raw=pd.DataFrame(data=dict)
statedata_raw.to_csv(apath+'state_data.csv',index=False)
statedata_raw2=pd.read_csv(apath+'state_data.csv')
statedata_raw2.to_csv(apath+'state_data2.csv',index=False)
But when I try to run the first part manually, creating the first csv, and then run the second part through cron, the second read_csv statement fails. I checked the permissions on the state_data.csv file and they are fine. It's set to -rwxr-xr-x
To be specific: I first run this script manually through command line. It executes and creates state_data.csv. Then I check the permissions of state_csv, and they are -rwxr-xr-x
cat=['a','a','a','a','a','b','b','b','b','b']
val=[1,2,3,4,5,6,7,8,9,10]
columns=['cat','val']
data=[cat,val]
dict={key:value for key,value in zip(columns,data)}
statedata_raw=pd.DataFrame(data=dict)
statedata_raw.to_csv(apath+'state_data.csv',index=False)
and then this script via cron, which fails, and gives the error message below
statedata_raw2=pd.read_csv(apath+'state_data.csv')
statedata_raw2.to_csv(apath+'state_data2.csv',index=False)
This is the error that I get from the system
Traceback (most recent call last):
File "/users/michaelmader/wdtest.py", line 39, in <module>
statedata_raw2=pd.read_csv(apath+'state_data.csv')
File "/opt/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 676, in parser_f
return _read(filepath_or_buffer, kwds)
File "/opt/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 448, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "/opt/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 880, in __init__
self._make_engine(self.engine)
File "/opt/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 1114, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/opt/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 1891, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 374, in pandas._libs.parsers.TextReader.__cinit__
File "pandas/_libs/parsers.pyx", line 678, in pandas._libs.parsers.TextReader._setup_parser_source
OSError: Initializing from file failed
To summarize
Run complete script through Terminal: state_data2.csv is created: pass
Run complete script through cron: state_data2.csv is created: pass
Run first part through Terminal, second part through cron: fail
I am on MacOS and I already gave crontab full disk access in system preferences.
I figured out the problem. The issue was the permissions that were granted to cron in MacOS. I thought I had solved it by giving \usr\bin\crontab full disk access, but I actually needed to give full disk access to usr\sbin\cron
The steps for doing this can be found here: https://blog.bejarano.io/fixing-cron-jobs-in-mojave/.
Once I made that change everything worked fine.

Indexing audio to get timestamps for each word using python

I have an audio file and I want to get the timestamps for each word. I want to know during which time period was each the words spoken.
(For example if an audio file says "I am a doctor" I want to know during which instant "I" was said, "am" was said and so on)
I want to do this using python.
I have tried the following code.
from SimpleAudioIndexer import SimpleAudioIndexer as sai
indexer = sai(mode="ibm", src_dir="D:/Codes/Python/audio recognition",
username_ibm="", password_ibm="")
indexer.index_audio(basename = "target.wav")
indexer.save_indexed_audio("{}/indexed_audio".format(indexer.src_dir))
indexer.load_indexed_audio("{}/indexed_audio.txt".format(indexer.src_dir))
print(indexer.get_timestamps())
However I am running into following error.
Traceback (most recent call last):
File "D:\Codes\Python\audio recognition\rec.py", line 5, in <module>
indexer.index_audio(basename = "target.wav")
File "C:\Users\Awais\AppData\Roaming\Python\Python37\site-
packages\SimpleAudioIndexer\__init__.py", line 1108, in index_audio
self._index_audio_ibm(*args, **kwargs)
File "C:\Users\Awais\AppData\Roaming\Python\Python37\site-
packages\SimpleAudioIndexer\__init__.py", line 928, in _index_audio_ibm
replace_already_indexed=replace_already_indexed)
File "C:\Users\Awais\AppData\Roaming\Python\Python37\site-
packages\SimpleAudioIndexer\__init__.py", line 730, in _prepare_audio
self._filtering_step(basename)
File "C:\Users\Awais\AppData\Roaming\Python\Python37\site-
packages\SimpleAudioIndexer\__init__.py", line 638, in _filtering_step
universal_newlines=True).communicate()
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python37_64\lib\subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python37_64\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
From what I can tell from your code/errors is that you're running Windows, but you're using forward slashes "/" in your src_dir string. This won't work as Windows uses the backslash "\" when navigating folders. Such as:
C:\Windows
while many Unix based systems use the forward slash like this:
/home/Awais
In your code you should try to change the "/" to "\" and see if that makes a difference.
If it is your intention on using this program on both Windows and Unix systems, you should use python3's "pathlib" to ensure your directory paths work on either OS. Here is a link that you can use to learn more about handling paths in python3:
https://medium.com/#ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f

FileNot FoundError:fluidsynth

I just want to convert my midi files to mp3 by using midi2audio, i use this code:
----------
from midi2audio import FluidSynth
FluidSynth().midi_to_audio('test.mid','test.mp3')
---------- or
from midi2audio import FluidSynth
FluidSynth().play_midi('test.mid')
but i got the same result:
----------
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/blake/Desktop/Bsmart_music/test/t_p/1.py
Traceback (most recent call last):
File "/Users/blake/Desktop/Bsmart_music/test/t_p/1.py", line 5, in <module>
FluidSynth().play_midi('test.mid')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/midi2audio.py", line 49, in play_midi
subprocess.call(['fluidsynth', '-i', self.sound_font, midi_file, '-r', str(self.sample_rate)])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'fluidsynth': 'fluidsynth'
Process finished with exit code 1
----------
So, i try to copy the fold "fluidsynth" to "midi2audio", but it still doesn't work. I have installed both midi2audio and fluidsynth, who knows what happened?
you must copy "fluidsynth" in some folder pointed by your PATH environ variable
( type "echo $PATH" in terminal app to see what is registered actually ).
On unix-like systems python will usually find fluidsynth located at /usr/bin/fluidsynth ( as /usr/bin is listed in the PATH ). on Os X things are not much different any documentation should fit. A common practice is to use /usr/local/bin folder for adding custom programs.
Maybe you should install fluidsynth first
for ubuntu:
sudo apt-get install fluidsynth

Subprocess library won't execute compgen

I am trying to make list of every command available on my linux (Lubuntu) machine. I would like to further work with that list in Python. Normally to list the commands in the console I would write "compgen -c" and it would print the results to stdout.
I would like to execute that command using Python subprocess library but it gives me an error and I don't know why.
Here is the code:
#!/usr/bin/python
import subprocess
#get list of available linux commands
l_commands = subprocess.Popen(['compgen', '-c'])
print l_commands
Here is the error I'm getting:
Traceback (most recent call last):
File "commands.py", line 6, in <module>
l_commands = subprocess.Popen(['compgen', '-c'])
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I'm stuck. Could you guys help me with this? How to I execute the compgen command using subprocess?
compgen is a builtin bash command, run it in the shell:
from subprocess import check_output
output = check_output('compgen -c', shell=True, executable='/bin/bash')
commands = output.splitlines()
You could also write it as:
output = check_output(['/bin/bash', '-c', 'compgen -c'])
But it puts the essential part (compgen) last, so I prefer the first variant.
I'm not sure what compgen is, but that path needs to be absolute. When I use subprocess, I spell out the exact page /absolute/path/to/compgen

Segmentation fault (core dumped) while calling python script from NodeJS through spawn

I have python script which prints out long list through statistical R (by PypeR). This python script is working absolutely fine.
Now I am trying to run this script from NodeJS through spawn functionality of child_process but it fails with following error:-
Traceback (most recent call last):
File "pyper_sample.py", line 5, in <module>
r=R()
File "/home/mehtam/pyper.py", line 582, in __init__
'prog' : Popen(RCMD, stdin=PIPE, stdout=PIPE, stderr=return_err and _STDOUT or childstderr, startupinfo=info),
File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
./temp.sh: line 1: 27500 Segmentation fault (core dumped) python pyper_sample.py o1dn01.tsv cpu_overall
child process exited with code : 139
Note: My python script is working perfectly. I already tested it manually.
My python script is working perfectly. I already tested it manually.
The output clearly shows that OSError: No such file or directory exception happened during Popen() call.
It means that the program is not found e.g.,
>>> from subprocess import Popen
>>> p = Popen(["ls", "-l"]) # OK
>>> total 0
>>> p = Popen(["no-such-program-in-current-path"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Also, passing the whole command as a string instead of a list (shell=False by default) is a common error:
>>> p = Popen("ls -l")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Make sure:
your (child) program can be found in current $PATH
use a list argument instead of a string
test whether it works if you run it manually from a different working directory, different user, etc
Note: your Popen() call passes startupinfo that is Windows only. A string command with several arguments that would work on Windows fails with the "No such file or directory" error on Unix.

Resources