ENVIRONMENT : Windows 10 & Python 3.7
I am trying to test if some programs are installed on a computer with Python 3.7
I am using this code:
print(f"p_command:{p_command}")
proc = subprocess.Popen(p_command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, close_fds=True)
returncode = proc.wait()
print(f'returncode : {returncode} - {type(returncode)}')
output = proc.stdout.read()
try:
output = output.decode('utf-8')
except Exception as ex:
logger.error(f"ERROR with TestIfInstalled => output = output.decode('utf-8'): {ex} ")
When I try to see if "node" is installed with the command (p_command) : "node --version" but it bugs! This is the output:
p_command:node --version
returncode : 1 - <class 'int'>
ERROR with TestIfInstalled => output = output.decode('utf-8'): 'utf-8' codec can't decode byte 0x82 in position 82: invalid start byte
output : b"'node' is not recognized as an internal command\r\nou externe, un programme ex\x82cutable ou un fichier de commandes.\r\n" returncode : 1
So I tested from my terminal by typing manually node --version" and I get correct answer because it is installed and it path is in environment variable PATH:
C:\Users\gauth>node --version
v12.15.0
C:\Users\gauth>
This is the content of PATH:
PATH=C:\Program Files\Common Files\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:
\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\wamp64\bin\php\php7.4.9;C:\Program Files\PuTTY\;C:\MinGW64\bin;C:\Qt\QtIFW-4.1.0;C:\Program Files\Git\cmd;C:\Windows\System32;C:\Pro
gram Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\nodejs\;C:\Users\gauth\AppData\Local\Android\cmdline-to
ols\tools\bin;C:\Users\gauth\AppData\Local\Android\platform-tools;C:\Users\gauth\AppData\Local\Android;C:\Users\gauth\AppData\Local\Android\build-tools\28.0.3;C:\Program Files\Tesseract-O
CR\tessdata;C:\Program Files\Tesseract-OCR;C:\Program Files (x86)\nodejs\node_modules\npm\bin;C:\Users\gauth\AppData\Local\Android\tools\lib\x86_64;C:\Users\gauth\AppData\Local\Android\to
ols;C:\Users\gauth\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\gauth\AppData\Local\Programs\Python\Python37\;C:\Users\gauth\AppData\Local\Microsoft\WindowsApps;C:\Users\gauth
\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\bin;C:\Users\gauth\AppData\Roaming\npm;C:\Users\gauth\AppData\Local\GitHubDeskt
op\bin
So as a result, I suppose my Python script is not loading properly in the PATH environment? How to force python to load all the values from PATH in memory in order to execute properly the command "node --version"? Can you help, please?
WHAT DID I TRY?
I tried to print the value of "PATH" from my python script:
Path = os.getenv('Path')
print(f"Path:{Path}")
OUTPUT:
Path:C:\Users\gauth\AppData\Local\Programs\Python\Python37\lib\site-packages\cv2\../../x64/vc14/bin;C:\Users\gauth\AppData\Local\Programs\Python\Python37\lib\site-packages\PyQt5\Qt5\bin;C:\Users\gauth\AppData\Local\Programs\Python\Python37\lib\site-packages\pywin32_system32;C:\Program Files\Common Files\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\wamp64\bin\php\php7.4.9;C:\Program Files\PuTTY\;C:\MinGW64\bin;C:\Qt\QtIFW-4.1.0;C:\Program Files\Git\cmd;C:\Windows\System32;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\nodejs\;C:\Users\gauth\AppData\Local\Android\cmdline-tools\tools\bin;C:\Users\gauth\AppData\Local\Android\platform-tools;C:\Users\gauth\AppData\Local\Android;C:\Users\gauth\AppData\Local\Android\build-tools\28.0.3;C:\Program Files\Tesseract-OCR\tessdata;C:\Program Files\Tesseract-OCR;C:\Program Files (x86)\nodejs\node_modules\npm\bin;C:\Users\gauth\AppData\Local\Android\tools\lib\x86_64;C:\Users\gauth\AppData\Local\Android\tools;C:\Users\gauth\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\gauth\AppData\Local\Programs\Python\Python37\;C:\Users\gauth\AppData\Local\Microsoft\WindowsApps;C:\Users\gauth\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\bin;C:\Users\gauth\AppData\Roaming\npm;C:\Users\gauth\AppData\Local\GitHubDesktop\bin;C:\Users\gauth\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\.libs
As you can see, there is the node path in it.