FileNotFoundError: [WinError 2] The system cannot find the file specified

Hello guys,

I am trying to run the script below in python and I keep getting this error
[FileNotFoundError: [WinError 2] The system cannot find the file specified]

Script
#open with Google Earth pro
subprocess.call([‘open’, lines_kml_flyingpath]);

I appreciate your support guys, thank you in advance.

What was the file specified, and does it actually exist?

Please copy and paste the full error message, starting with the line
“Traceback”. It would also help if you could show the value of your
lines_kml_flyingpath variable.

Thank you for the reply Stevan,

here you go:

Traceback (most recent call last):
File “C:/Users/alkon/PycharmProjects/KML file by python/main.py”, line 43, in
subprocess.call([‘open’, lines_kml_flyingpath]);
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

Process finished with exit code 1

it is a route kml file and yes it exists, was created in the same script

Please copy and paste the line of code that assigns
the variable lines_kml_flyingpath.

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).

I attached below the complete code, its small.

Script*

import simplekml
import subprocess
import pandas as pd

#Germany1 52.17365048266471, 10.50326921341822
#Germany2 52.17428145858134, 10.50385051351152

lines_kml = simplekml.Kml()
lines = lines_kml.newlinestring(name=‘flyingath’,
description=‘Germany1 to Germany2’,
coords=[(10.50326921341822,52.17365048266471),
(10.50385051351152,52.17428145858134)])

#change the line width and color
lines.style.linestyle.width = 5
lines.style.linestyle.color = simplekml.Color.red

Lines_kml_flyingath = ‘/Users/alkon/PycharmProjects/Lines_kml.kml’
lines_kml.save(Lines_kml_flyingpath)

#open with Google Earth pro
subprocess.call([‘open’, lines_kml_flyingpath]);

Thank you man for your help.
unfortunately, I tried it and it gave me the same error.

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 internal start 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.