如,在/home/abc/dex/下有test.py,如果我cd /home/abc/dex/,再运行python test.py 这样是没有问题的
但是如果我在/home下,python abc/dex/test.py 或者python /home/abc/dex/test.py 这样运行就报[Errno 2] No such file or directory
请求帮忙,谢谢!
如,在/home/abc/dex/下有test.py,如果我cd /home/abc/dex/,再运行python test.py 这样是没有问题的
但是如果我在/home下,python abc/dex/test.py 或者python /home/abc/dex/test.py 这样运行就报[Errno 2] No such file or directory
请求帮忙,谢谢!
检查下你的代码中是否有获取当前路径的代码,造成所需要的文件的路径出现的错误,比如你获取路径是获取当前所处路径,你cd /home/abc/dex/到这个路径它获取的就是/home/abc/dex/路径,但是你在/home下,python abc/dex/test.py 它获取的路径可能会变成/home
解决方式:把涉及到的路径改成绝对路径,或者加上这句os.chdir("/home/abc/dex/")