python: can't open file 'xx.py': [Errno 2] No such file or directory

python: can't open file 'xx.py': [Errno 2] No such file or directory

C:\Users\Administrator>python xx.py
python: can't open file 'xx.py': [Errno 2] No such file or directory

C:\Users\Administrator>cd Desktop\

C:\Users\Administrator\Desktop>python xx.py
hello, world

以上出现了文件路径错误的提示。上面标红的内容是关键。通过cd转路径。默认没有Desktop这个层级,而.py文件又在这个层级之下,因此直接在上上级打开.py文件是会报错的。

还有一种,如果把.py文件从c盘放到了d盘,那么:

C:\Users\Administrator>cd D:\software\pythonexcese

C:\Users\Administrator>D:\

即可转化路径为D盘。

python: can't open file 'xx.py': [Errno 2] No such file or directory:等您坐沙发呢!

发表评论

表情
还能输入210个字