无法打开文件“hello_world.py”:[Errno 2]没有这样的文件或目录

2024-10-03 19:20:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用“python速成课程第二版”学习代码,第一个设置之一是学习从终端运行“python_world.py”。我在Mac上运行这个程序。每当我输入代码以运行代码时,它都会给我以下错误消息:

Last login: Fri Nov  6 03:01:42 on ttys000
richardortiz-caballero@Richards-MacBook-Pro ~ % cd Desktop
richardortiz-caballero@Richards-MacBook-Pro Desktop % ls
Screen Shot 2020-08-27 at 12.07.12 PM.png
Screen Shot 2020-09-14 at 11.11.37 PM.png
Screen Shot 2020-09-17 at 11.10.25 PM.png
Screen Shot 2020-10-07 at 1.14.24 PM.png
Screen Shot 2020-10-07 at 2.00.35 PM.png
Screen Shot 2020-10-07 at 3.42.37 PM.png
Screen Shot 2020-10-11 at 10.44.14 PM.png
Screen Shot 2020-10-15 at 8.05.42 PM.png
python_work
richardortiz-caballero@Richards-MacBook-Pro Desktop % ls python_work
hello_world.py
richardortiz-caballero@Richards-MacBook-Pro Desktop % python hello_world.py
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'hello_world.py': [Errno 2] No such file or directory

Tags: 代码pyhelloworldpngscreenatpro
1条回答
网友
1楼 · 发布于 2024-10-03 19:20:14

您需要在文件的目录中才能运行该文件。在键入python hello_world.py之前,您需要输入目录。因此,首先使用cd python_work

或者,如果要从桌面目录运行,只需在运行时使用完整路径: python python_work/hello_world.py

相关问题 更多 >