Traceback (most recent call last):
File “C:/Users/alkon/PycharmProjects/KML file by python/main.py”, line 43, in
File “C:\python3\lib\subprocess.py”, line 340, in call
with Popen(*popenargs, **kwargs) as p:
File “C:\python3\lib\subprocess.py”, line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “C:\python3\lib\subprocess.py”, line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
The above call looks for a file named “open” or “open.exe” in the default executable-file search path. There’s no standard “open.exe” file in Windows, so this error is what I’d expect. If you want to open the KML file according to its registered file association, use os.startfile(lines_kml_flyingpath).
If os.startfile(lines_kml_flyingpath) raises FileNotFoundError, then it’s the KML file itself that can’t be found, as opposed to “open.exe” with the original subprocess call. Your script has lines_kml_flyingath = '/Users/alkon/PycharmProjects/Lines_kml.kml'. I suggest using a fully-qualified path with a drive, e.g. lines_kml_flyingpath = "C:/Users/alkon/PycharmProjects/Lines_kml.kml". Also, right after saving the file, check to ensure that it exists via assert os.path.isfile(lines_kml_flyingpath).
Thank you a lot man now it works perfectly and there’s no error anymore.
After running the script, the KML file opened in Notepad but I was also trying to open it right away in google earth and it didn’t.
I have seen a youtube video where they used subprocess.call([‘open’, lines_kml_flyingpath]);
and the route was opened directly in google earth, why isn’t it working in my script?
Thank you again for your support and your time.
The file is opened with the registered handler for .kml files. If you want Google Earth to handle them, check whether it has an option to take control of the .kml file extension, or manually change the file association in Explorer.
The video capture was probably recorded on a macOS system, which has an open command. On Linux desktops there’s usually a comparable xdg-open command. Windows has no such external command that can be executed with subprocess. The CMD shell in Windows does have an internalstart command that’s similar. You can use it with subprocess with shell=True. However, for just opening a file, it’s effectively the same, but simpler and safer, to just use os.startfile().
Alright man, I get it, thanks a lot it was really helpful.
I have one last question. I have defined the first and last coordinates of the route which I have as you saw in the script.
How can I add 10 waypoints for example on this route with a distance of 1 m between each coordinate until reaching the last coordinate? I did it manually by typing the other coordinates as well, not just the first and the last, but this is a waste of time and I believe it can be done with a just simple function.