Python——Bug解决:文件存在但os.path.exists或os.path.isfile返回false

问题

  • python脚本访问路径,前一级路径存在,但文件不存在:
bash 复制代码
(Pdb) os.path.isfile(f"/mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin")
False
(Pdb) os.path.isfile(f"/mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is")
True
  • 命令行ls看,是存在的:
bash 复制代码
>>> ls /mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin
/mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin

可能问题原因及解决方法

1.

2.

  • 给权限即可。

反转

  • 但我发现这个权限也没问题,而且最重要的是我发现它只是个软链接,因此这个文件不存在极可能是由于原文件不存在了
bash 复制代码
>>> ls -l /mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin
lrwxrwxrwx 1 gaohongzhi gaohongzhi 179 Nov  2 15:38 /mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin -> ../../../../../../.cache/huggingface/hub/models--lorahub--flan_t5_large-adversarial_qa_dbert_tell_what_it_is/blobs/37a8d9c6732bfab95b168e90e02363d8a254ad1ac208fc32f9e61b2c693f5230
  • 果然这玩意就什么都不是!所以还是文件有问题导致的!
bash 复制代码
>>> ls -l /.cache/huggingface/hub/models--lorahub--flan_t5_large-adversarial_qa_dbert_tell_what_it_is/blobs/37a8d9c6732bfab95b168e90e02363d8a254ad1ac208fc32f9e61b2c693f5230
相关推荐
玄同7658 小时前
我是如何学习编程的?——从 “扳手使用” 到编程学习:踩坑式实践的底层方法论
开发语言·人工智能·经验分享·笔记·python·学习·自然语言处理
Java后端的Ai之路8 小时前
【Python进阶学习】-NumPy详细介绍指南(附demo)
python·学习·numpy
xingzhemengyou18 小时前
Python lambda函数
开发语言·python
Geoking.8 小时前
【Java】深入理解 Java 枚举(Enum)
java·开发语言
老王熬夜敲代码9 小时前
C++新特性:string_view
开发语言·c++·笔记
像风一样的男人@9 小时前
python --生成ico图标
java·python·spring
zhaokuner9 小时前
06-聚合与一致性边界-DDD领域驱动设计
java·开发语言·设计模式·架构
CNRio9 小时前
Day 45:Git的高级技巧:使用Git的bisect快速定位bug
git·elasticsearch·bug
lsx2024069 小时前
Ionic 卡片组件深度解析
开发语言
多打代码9 小时前
2026.1.2 删除二叉搜索树中的节点
开发语言·python·算法