[英]command prompt says "No such file or directory" but the file exists
我在命令提示符下运行文件时遇到问题,一直说“没有这样的文件或目录”
我复制 n 粘贴了现有文件的路径,然后将文件与我被告知不存在的文件交换。 还尝试了语法的各种小变化。
在文本编辑器中:
from sys import argv
script, filename = argv
txt = open(filename)
print(f"heres the file you wanted:{filename}:")
print(txt.read())
print("type the filename again:")
file_again=input("> ")
txt_again=open(file_again)
print(txt_again.read())
在 BASH 中:
python3.7 /users/philipedwards/Documents/ex15.py test.txt
我假设test.txt
在Documents
文件夹中。 但是,基于此命令:
python3.7 /users/philipedwards/Documents/ex15.py test.txt
您当前的位置可能不是Documents
目录。 通过指定text.txt
您试图从当前目录打开text.txt
,而不是/users/philipedwards/Documents/test.txt
。
因此,要么从Documents
目录运行脚本:
cd /users/philipedwards/Documents
python3.7 ex15.py test.txt
或者,如果您不想更改活动目录,请指定文本文件的完整路径:
python3.7 /users/philipedwards/Documents/ex15.py /users/philipedwards/Documents/test.txt
对于未来面临这个问题的人。 这可能是因为二进制文件是 32Bits 或任何不兼容的架构。 这是一个引用相同问题的优秀线程: 没有这样的文件或目录? 但是文件存在!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.