如何修复“无法打开文件 'Test.py':[Errno2] 没有这样的文件或目录"? [英] How to fix "cannot open file 'Test.py': [Errno2] No such file or directory"?

查看:121
本文介绍了如何修复“无法打开文件 'Test.py':[Errno2] 没有这样的文件或目录"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我尝试运行当前文件夹中不存在的python脚本

I tried to run a python script which does not exist in current folder, for example

C:\>python Test.py

python:can't open file 'Test.py':[Errno2] 没有那个文件或目录

python:can't open file 'Test.py':[Errno2] No such file or directory

我必须指定绝对路径 c:\testdir\test.py 才能使命令可用.

I have to specify the absolute path c:\testdir\test.py to make the command workable.

c:\python c:\testdir\Test.py

我尝试将 "c:\testdir" 附加到 Env 参数 'PATH' 中,但它仍然不起作用.

I tried to append "c:\testdir" into Env argument 'PATH', but it still doesn't work.

我想使用文件名而不是整个路径,c:\python 测试.py我能做到吗?

i want to use the filename rather than the entire path, c:\python Test.py can i make it happen?

推荐答案

这意味着您当前不在 C:/testdir(您在 C:).在终端中输入 cd C:\testdir 以移动到该目录(cd = change directory).

That means you're not currently in C:/testdir (you're in C:). Enter cd C:\testdir in your terminal to move to that directory (cd = change directory).

必须在文件夹外指定整个路径的原因是,即使您不在要引用的文件夹中,您仍然可以使用其路径来引用它.

The reason you have to specify the entire path while out of the folder is because even if you're not in the folder that you're trying to reference, you can still use its path to reference it.

这篇关于如何修复“无法打开文件 'Test.py':[Errno2] 没有这样的文件或目录"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆