文件路径中的空格导致问题(windows shell 和 python)

Whitespaces in filepath causing problems (windows shell and python)

我正在制作一个程序,将 .py 个文件转换为 .exe 个文件。我让它正常工作,但我发现如果文件路径中有任何空格,程序就会失败。此路径将失败,例如:

 C:\Users\Emilio\Desktop\Python\Python to Exe - Tkinter - Pyinstaller\py2exe.py

具体来说,每当将它传递给 windows shell 时都会失败,因为它不能采用带空格的文件路径。这是在 cmd 上失败的命令:

 pyinstaller C:\Users\Emilio\Desktop\Python\Python to Exe - Tkinter - Pyinstaller\Py2Exe.py

有什么解决方法?

在它周围加上引号应该可以解决您的问题。

"C:\Users\Emilio\Desktop\Python\Python to Exe - Tkinter - Pyinstaller\py2exe.py"

要么双引号路径,要么转义它:

"C:\Users\Emilio\Desktop\Python\Python to Exe - Tkinter - Pyinstaller\py2exe.py"

转义:

C:\Users\Emilio\Desktop\Python\Python\ to\ Exe\ -\ Tkinter\ -\ Pyinstaller\py2exe.py