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

yanghartai 2019-04-24 10:58:16
在当前目录下,运行位于另外一个目录的py文件。

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

如果指定了文件的全路径,运行正常
C:\>python c:\testdir\Test001.py
this is a test

我试图将c:\testdir加入到系统环境变量PATH里,但是仍然报错,can't open file 'Test001.py': [Errno 2] No such file or directory

是不是如果运行的py脚本不在当前目录下,就必须要指定全路径?

...全文
8387 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Steven·简谈 2019-04-25
  • 打赏
  • 举报
回复
为什么有这个需求,如果是运行的话还是全路径,如果是想添加库的话就放在Python目录中的 \Lib\site-packages 文件夹下

37,741

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧