I try to execute command in cmd from Python and save the output. I have the following code:
import subprocess
import matplotlib.pyplot as pyplot
MyOut = subprocess.Popen("pytr portfolio",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout,stderr = MyOut.communicate()
chart_data = []
days = []
t = 0
new_char = stdout.split()
print(new_char)
netValue = float(new_char[new_char.index(b'netValue') + 2])
file = open('netValue.txt','a')
file.write(str(netValue))
file.write('\n')
file.close()
file = open('netValue.txt','r')
for line in file:
t += 1
print(line)
chart_data.append(line)
days.append(t)
file.close()
pyplot.plot(days,chart_data)
pyplot.title('depot_performance')
pyplot.show()
On my pc it works well but when I run this on my laptop i get the following error message:
Traceback (most recent call last):
File "c:\Users\dinok\OneDrive\Desktop\Python_Scripts\depot_statistics.py", line 9, in <module>
MyOut = subprocess.Popen("pytr portfolio",
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
I thought it is path related so that the module is not found but was not able to find a solution. What could cause this problem and how to fixt it?