关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”
今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到“FileNotFoundError: [Errno 2] No such file or directory: '1528712892362.jpg'”这个问题。
讲讲解决方案,因为我要处理的十几张图片是位于 ‘F:\图片’ 这个路径下的,但是读取到具体的某一个文件时忘记使用绝对路径,如果没有为文件加上前面的绝对路径的话,我的理解是默认在程序所在的路径作为当前路径来查找的,所以就会报错说找不到文件。
后来加上代码中的第10行,并在16行中稍作修改就行了。
import os
from PIL import Image
SQUARE_FIT_SIZE=500
LOGO_FILENAME='catlogo.png'
logoIm=Image.open(LOGO_FILENAME)
width1,height1=logoIm.size
logoIm1=logoIm.resize((int(width1/5),int(height1/5)))
logoWidth,logoHeight=logoIm1.size
logoIm=logoIm1
root='F:/图片/'
os.makedirs('withLogo',exist_ok=True)
for filename in os.listdir('F:\图片'):
print(filename)
if not (filename.endswith('.png') or filename.endswith('.jpg')) or filename==LOGO_FILENAME:
continue
im=Image.open(root+filename)
width,height=im.size
print('Resizing %s...'%(filename))
im=im.resize((width,height))
print('Adding logo to %s...'%(filename))
im.paste(logoIm,(width-logoWidth,height-logoHeight),logoIm)
im.save(os.path.join('withLogo',filename))
关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”的更多相关文章
- 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...)
环境: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 ...
- FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决
FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题 最近在学习爬虫,想爬一些图片并保存到本地,但是在下载图片 ...
- 对于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 ...
- 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中左 ...
- Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt
最近安装python,已经安装好,cmd终端中输入python.pip等命令都有用 然而在配置requirements.txt文件过程中,执行语句 “pip install -r requiremen ...
随机推荐
- linux命令:linux权限管理命令
权限管理命令 文件的权限只有你两个人可以更改,一个是root,一个是文件所有者. 命令名称:chmod 命令英文原意:change the permissions mode of a file ...
- STA分析(二) multi_cycle and false
multicycle path:当FF之间的组合逻辑path propagate delay大于一个时钟cycle时,这条combinational path能被称为multicycle path. ...
- Rpgmaker开发心得(1)且事件
例:NPC让你给他桃子和梨子,然后给你西瓜. 实际就是:有桃子且有梨子时的判断,但对于大多数不会直接编写脚本的同学,最好的方式就是使用开关. 思路如下: var:变量 on:开关 if(on西瓜=on ...
- n的相反数
实例十:n的相反数 方法:result=(~n)+1 正数 负数 原数 0000 0011 1111 1111补码 1111 1100 0000 0010加一 1111 1011 0000 001 ...
- EditPlus 5.1.2066 中文版(1月30日修正)
之前有一些网友反馈汉化版的 EditPlus 中翻页键无法正常工作.经过调查,发现是翻译工具的问题. 因此,我用新的工具重新翻译了 EditPlus.翻页键在新中文版中应该可以正常工作了. 有需要的网 ...
- HTTP 超文本协议
转载 :http://mp.weixin.qq.com/s/3d3zhksViX2NTuIssiYGJg
- linux常用命令:traceroute 命令
通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...
- MySQL用sql复制表数据到新表的方法
用sqlyog无法直接复制出一个不同表名的表来,只能copy到其他库上同名的表. 在MySQL数据库中,应该如何用sql将表数据复制到新表中呢? 本人通过试验测试成功了,而且相当简单易懂,速度也非常快 ...
- nginx做http向https的自动跳转
在访问百度时,在浏览器输入www.baidu.com会自动跳转到https://www.baidu.com不用人工干预,nginx也可以做这样的自动跳转! 首先让nginx服务器监听两个端口,分别是8 ...
- 20145106《Java程序设计》第7周学习总结
教材学习内容总结 使用Lambda的特性可以去除重复的信息,以取得语法的简洁,增加程序代码的表达性.Lambda表达式本身是中性的,不代表任何类型的实例,同样的Lambda表达式,可用来表示不同目标类 ...