FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决
FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题
最近在学习爬虫,想爬一些图片并保存到本地,但是在下载图片的时候遇到了各种问题,这里就说一下最后解决好了的问题。
(代码就不粘贴出来了哈)
按理来说,这个代码能够正常运行,因为我是跟着一个博主学的,可能是因为权限问题吧,我试过改过别的盘来存储运行,但是还是一样的结果。
运行之后出现这样的错误:

意思就是存不了。
解决方法:
法一:
1.导入os库
2.把要存放的路径复制一下,加上显示的格式
3.用os.path.expanduser()函数
4.正确找到路径
5.运行成功



法二:
还有一种方法就是在你的.py文件下建立一个独立的文件夹img存你下载下来的照片

然后使用'./img/’保存到文件夹里面
with open('./img/' + str(count) + '.jpg', mode="wb") as file:
运行成功:


以上是本人的一些小经验,如有不足,欢迎指正。
FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决的更多相关文章
- 关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”
今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到“FileNotFoundError: [Errno 2] No such file or directory: '152 ...
- python文件操作的坑( FileNotFoundError: [Errno 2] No such file or directory...)
环境:Windows8.1, Python3.6 pycharm community 2017 c盘下有一个配置文件:setup with open('c:\\setup','r') as ...
- 关于JPype报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误的解决
部署到线上的项目正常运行一年,今天早上突然报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误. JPyp ...
- Python中的用open打开文件错误,FileNotFoundError: [Errno 2] No such file or directory:
学习python的文件处理,刚开始打开文件,代码如下 f = open('test_file.txt', 'r', encoding='UTF-8')RES = f.readlines()print( ...
- 对于python中“FileNotFoundError: [Errno 2] No such file or directory”的解决办法
在我们使用vscode运行Python代码时遇到的情况 一.出现原因:这里是由于Vscode中,python里的路径是相对与工作目录来进行定位的.所以在多级目录情况下,若不设置绝对路径,往往找不到相应 ...
- FileNotFoundError: [Errno 2] No such file or directory的解决方法
1.获取当前文件所在路径 basedir = os.path.dirname(__file__) print("basedir:" + basedir) 2.将路径进行拼接 upl ...
- python3 使用selenium +webdriver打开chrome失败,报错:FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
提示chrome driver没有放置在正确的路径下 解决方法: 1.chromedriver与chrome各版本及下载地址 驱动的下载地址如下: http://chromedriver.storag ...
- RHEL 5.7 Yum配置本地源[Errno 2] No such file or directory
在Red Hat Enterprise Linux Server release 5.7 上配置YUM本地源时,遇到了"Errno 5] OSError: [Errno 2] No such ...
- VSCode python 遇到的问题:vscode can't open file '<unprintable file name>': [Errno 2] No such file or directory
代码很简单,就两行: import pandas as pd import netCDF4 as nc dataset = nc.Dataset('20150101.nc') 环境:在VSCode中左 ...
随机推荐
- LinuxCNC中RS-274/NGC解析器的编译和使用
原文 http://blog.sina.com.cn/s/blog_a2a6dd380102vrai.html LinuxCNC是一个著名的开源数控软件,目前最新发行版本是:LinuxCNC 2.6. ...
- Badger简单使用
Badger简介 badger 是 dgraph 开源的 LSMTree 的 KV 引擎,它相比 leveldb 有 KV 分离.事务.并发合并等增强,是 go 生态中比较生产级的存储引擎了. 文档: ...
- 常用写法java
迭代器遍历[List.Set.Map] 遍历List方法一:普通for循环 1 for(int i=0;i<list.size();i++){//list为集合的对象名 2 String tem ...
- SpringCloud 教程 | 第一篇: 服务的注册与发现Eureka(转载)
SpringCloud 教程 | 第一篇: 服务的注册与发现Eureka(Finchley版本) 转载请标明出处:http://blog.csdn.net/forezp/article/details ...
- Vue手动集成less预编译器
less是一门css预处理语言,简单的说就是在css的基础上提升为可编程性的预编译器 需要在项目中安装 less ,less-loader 2个插件,语法为:npm i -D less less-lo ...
- java-doc注释详解
注释的分类 // 注释一行/* ...... */ 注释若干行/** ...... */ 注释若干行,并写入 javadoc 文档 列子 /** * show 方法的简述. * <p>sh ...
- 客户端回调 Watcher?
客户端 SendThread 线程接收事件通知,交由 EventThread 线程回调 Watcher. 客户端的 Watcher 机制同样是一次性的,一旦被触发后,该 Watcher 就失效了.
- springboot使用redis实现发布与订阅
配置redis连接地址 # Redis服务器地址 spring.redis.host=youxiu326.xin # Redis服务器连接端口 spring.redis.port=6379 # Red ...
- ros中关于节点、话题、服务以及自定义消息等在终端中的常用命令
以下面的计算力图说明 节点相关常用命令 在终端中查看项目中有哪些节点命令:rosnode list 有了节点信息想要查看节点中到底发布订阅了哪些话题,作为服务端服务类型或者作为客户端需要的服务类型以上 ...
- (stm32f103学习总结)—stm32定时器中断
一.定时器介绍 STM32F1的定时器非常多,由2个基本定时器(TIM6.TIM7).4个通 用定时器(TIM2-TIM5)和2个高级定时器(TIM1.TIM8)组成.基本定 时器的功能最为简单,类似 ...