this is the code that I wrote:
import subprocess
rocket_league_path = 'D:\rocketleague\Binaries\Win64\RocketLeague.exe'
subprocess.Popen(rocket_league_path)
this is the error it shows to me:
Traceback (most recent call last):
File "c:\Users\Marco\Desktop\Untitled-1.py", line 7, in <module>
subprocess.Popen(rocket_league_path)
File "C:\Users\Marco\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Marco\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Cannot find the specified file
I have tried with other applications and it works with all except Rocket League
It's a quirk of the way string literals work in Python. The \
character is special, it indicates that the following characters may be interpreted as a special character. Or it may not, depending on what follows. In your case the two characters \r
are being converted to a single character Carriage Return. The path is now incomplete and the file can't be found. If it had been \c
instead it would have worked, because there's no special character corresponding to \c
.
You can easily fix it by using a raw character string instead, where the \
loses its special meaning.
rocket_league_path = r'D:\rocketleague\Binaries\Win64\RocketLeague.exe'
# ^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.