简体   繁体   English

为什么FileNotFoundError:[错误2]没有这样的文件或目录?

[英]Why FileNotFoundError: [Errno 2] No such file or directory?

debian8@debian:~$ ls -al /home/debian8/.mozilla/firefox/3usaclqf.default/lock  
lrwxrwxrwx 1 debian8 debian8 15 Jun 19 18:58 /home/debian8/.mozilla/firefox/3usaclqf.default/lock -> 127.0.1.1:+2815

The file /home/debian8/.mozilla/firefox/3usaclqf.default/lock is a link. 文件/home/debian8/.mozilla/firefox/3usaclqf.default/lock是一个链接。

debian8@debian:~$ python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58) 
>>> import os
>>> file1="/tmp/.X0-lock"
>>> print(os.stat(file1))
os.stat_result(st_mode=33060, st_ino=8126472, st_dev=2050, st_nlink=1, st_uid=0, st_gid=0, st_size=11, st_atime=1497877067, st_mtime=1497868886, st_ctime=1497868886)
>>> file2="/home/debian8/.mozilla/firefox/3usaclqf.default/lock"
>>> print(os.stat(file2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/home/debian8/.mozilla/firefox/3usaclqf.default/lock'

Why os.stat can't get infos on file2? 为什么os.stat无法获得有关file2的信息?

Does the file it is linked to exist? 链接的文件是否存在? os.stat() follows symlinks. os.stat()遵循符号链接。 If you want to stat the link file, you need os.lstat() 如果要统计链接文件,则需要os.lstat()

也许您无权打开此文件。尝试sudo chmod 777 /home/debian8/.mozilla/firefox/3usaclqf.default/lock

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FileNotFoundError:[Errno 2]没有这样的文件或目录: - FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError [Errno 2] 没有这样的文件或目录: - FileNotFoundError [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录? - FileNotFoundError: [Errno 2] No such file or directory? FileNotFoundError:[错误2]没有这样的文件或目录,但是文件在那里 - FileNotFoundError: [Errno 2] No such file or directory, But the file is there FileNotFoundError: [Errno 2] 没有这样的文件或目录,但有一个文件 - FileNotFoundError: [Errno 2] No such file or directory but there is a file FileNotFoundError: [Errno 2] 没有这样的文件或目录:&#39;ifconfig&#39; - FileNotFoundError: [Errno 2] No such file or directory: 'ifconfig' 错误:FileNotFoundError:[Errno 2] 没有这样的文件或目录 - Bad: FileNotFoundError: [Errno 2] No such file or directory python:FileNotFoundError:[Errno 2]没有这样的文件或目录 - python: FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError:[错误2]没有这样的文件或目录 - Python FileNotFoundError: [Errno 2] No such file or directory FileNotFoundError:[错误2]没有这样的文件或目录:错误 - FileNotFoundError: [Errno 2] No such file or directory: error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM