我正在使用'python crash course Second Edition‘学习代码,其中一个最早的设置是学习从终端运行'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发布于 2020-11-06 18:38:58
您需要在该文件所在的目录中才能运行它。在键入python hello_world.py之前,您需要输入目录。所以首先使用cd python_work。
或者,如果您想从桌面目录运行它,只需在运行它时使用完整路径:python python_work/hello_world.py
https://stackoverflow.com/questions/64712919
复制相似问题