Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 没有这样的文件或目录?_Python_Errno - Fatal编程技术网

Python 没有这样的文件或目录?

Python 没有这样的文件或目录?,python,errno,Python,Errno,我对“FileNotFoundError:[Errno 2]没有这样的文件或目录:'发音\数据.txt'有问题 我一直在将我的工作目录重置到正确的位置,但它似乎不想保留(使用Spyder/Anaconda)。我还尝试了以下方法: file = open(r'C:\path\to\Pronunciation_Data.txt\Users\stephaniecheetham\Desktop\Thesis') 导入操作系统 chdir(r'C:\Users\stephaniecheetham\Des

我对“FileNotFoundError:[Errno 2]没有这样的文件或目录:'发音\数据.txt'有问题

我一直在将我的工作目录重置到正确的位置,但它似乎不想保留(使用Spyder/Anaconda)。我还尝试了以下方法:

file = open(r'C:\path\to\Pronunciation_Data.txt\Users\stephaniecheetham\Desktop\Thesis')
导入操作系统
chdir(r'C:\Users\stephaniecheetham\Desktop\Thesis')
file=open('读音\数据.txt')
文件=打开(“读音_Data.txt”,“r”)
文件=打开(“\r\u Data.txt”,'r')
file=open(“C:/stephaniecheetham/Desktop/Thesis/personation_Data.txt,'r')
它们中的任何一个都不走运。只是相同的错误。我最近也遇到了一个模块问题,并使用
import os
命令修复了它


有什么建议吗?

为了帮助调试,您还可以执行os.listdir()以查看您是否位于正确的目录中


此外,还不清楚您的文件的完整路径应该是什么。C:/stephaniecheetham与C:/Users/stephaniecheetham不同。您的目录是否存在?通过执行以下操作检查您的文件是否存在:

导入操作系统
chdir('C:\Users\stephaniecheetham\Desktop\Thesis')
试一试{
文件=打开('prononucation\u Data.txt'))
}除了FileNotFoundError{
打印(“未找到文件”)
}

您的目录是否存在?请使用
os.listdir()

代码中有两个错误:

  • 您尚未导入
    os
    模块
  • 它们是第2行中的一个
    SyntaxError
    ,其中缺少一个括号

显而易见的答案是您在错误的目录中,或者使用了错误的文件名。在执行
os.chdir()
之后,向我们显示以下输出:
print(os.listdir())
。这将向我们显示该目录中的所有文件。这是否回答了您的问题?我怀疑她的真实代码有这些错误,或者她不会得到FileNotFoundError。
import os
os.chdir(r'C:\Users\stephaniecheetham\Desktop\Thesis')
file = open('Pronunciation_Data.txt')

file = open("Pronunciation_Data.txt",'r')

file = open("<Users/stephaniecheetham/Desktop/Thesis>\Pronunciation_Data.txt",'r')

file = open("C:/stephaniecheetham/Desktop/Thesis/Pronunciation_Data.txt",'r')