简体   繁体   中英

Errors trying to run a python script from a batch file

I have this line in my bat file:

C:\Python26\python.exe C:\myPythonDirectory.py

But it fails giving the error: can't open file [Errno2] no such file or directory.

Could it be giving an error because there is a space in one of the folder names in my python directory?

Absolutely. If there's a space in the path, you need to put the whole path in double quotes.

If there are spaces in the names of the directories you need to use the below code. For example, the name of the directory and the path is "D:\My New Bot\main.py" . as there is a gap between the words , python recognises only the first word and tries to find path as "D:\My" which does not exist. Please use the below code :

path = r"D:\My New Bot\main.py"

This will work.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM