Search code examples
python-3.xsubprocesspopen

Subprocess Popen couldn't find 'play'


Popen from subprocess couldn't find 'play' or 'aplay'.

My OS is Mac10.13.6, when I called Popen from subprocess.py and executed the flowing code

import platform
from subprocess import Popen

player = 'play' if platform.system() == 'Darwin' else 'aplay'
Popen([player, '-q', filename])

I received the following errors

  File "/Users/lyuzhiliang/mycroft-precise/precise/util.py", line 78, in play_audio
    Popen([player, '-q', filename])
  File "/Users/lyuzhiliang/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/Users/lyuzhiliang/anaconda3/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: 'play': 'play'

Do I need to install some dependencies?


Solution

  • I am not entirely sure, I think it has to be afplay. Maybe try to give the full path and look for the binary yourself. (I think /usr/bin/afplay)