I'm trying to run Docker commands from a Python script using the subprocess module. However, I keep getting the error /bin/sh: docker: command not found
. When I run the same command in the terminal, it works fine.
When I specify the full path
call('/usr/bin/docker version', shell=True)
it gives me /bin/sh: line 1: /usr/bin/docker: No such file or directory
. Confirmed it by running
call('cd /usr/bin/ && ls', shell=True)
and there's really no docker executable there (from terminal with the same environment, it's all fine).
I also tried to explicitly set the PATH variable, but it also gave no results. User permissions from both the python script and terminal are the same.
What could be causing this discrepancy?
I'm using:
Arch Linux
Docker version 26.1.3
Python 3.12.3
I realized that it's some problem with VSCode. I barely use it, so I guess I forgot to configure something or I don't know. Jun run it separately in a terminal and magically the script worked.