Python subprocess on Linux: no such file or directory
Question:
I am trying to get the install location of conda. This works fine on Windows:
conda_path = subprocess.check_output('where anaconda').decode("utf-8").strip()
In a linux shell whereis conda
works. os.system("whereis conda")
returns zero.
However,
conda_path = subprocess.check_output('where anaconda').decode("utf-8").strip()
Fails with: FileNotFoundError: [Errno 2] No such file or directory: 'whereis conda': 'whereis conda'
Any suggestions?
Answers:
If you pass a single string, you need a shell to parse it into the command name and its arguments: subprocess.check_output('where anaconda', shell=True)....
Otherwise, you need to provide a list where the command name and each argument is a separate element. (One of the primary jobs of a shell is to do precisely that parsing.)
conda_path = subprocess.check_output(['where', 'anaconda']).decode("utf-8").strip()
I am trying to get the install location of conda. This works fine on Windows:
conda_path = subprocess.check_output('where anaconda').decode("utf-8").strip()
In a linux shell whereis conda
works. os.system("whereis conda")
returns zero.
However,
conda_path = subprocess.check_output('where anaconda').decode("utf-8").strip()
Fails with: FileNotFoundError: [Errno 2] No such file or directory: 'whereis conda': 'whereis conda'
Any suggestions?
If you pass a single string, you need a shell to parse it into the command name and its arguments: subprocess.check_output('where anaconda', shell=True)....
Otherwise, you need to provide a list where the command name and each argument is a separate element. (One of the primary jobs of a shell is to do precisely that parsing.)
conda_path = subprocess.check_output(['where', 'anaconda']).decode("utf-8").strip()