当前位置: 代码迷 >> 综合 >> python3.7: PermissionError: [WinError 32] The process cannot access the file because it is......
  详细解决方案

python3.7: PermissionError: [WinError 32] The process cannot access the file because it is......

热度:66   发布时间:2023-12-12 22:16:25.0

问题描述:

python3.7 , 使用 PIL 里面的库 Image 只想获取图片的长和宽
报如下错误

D:\Python37-32\python.exe D:/pyFile/python_script/img_read.py
Traceback (most recent call last):
File “D:\Python37-32\lib\shutil.py”, line 557, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: ‘C:\Users\Adminroot\Desktop\app_delete\files\1.png’ -> ‘C:\Users\Adminroot\Desktop\test\350_500\1.png’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:/pyFile/python_script/img_read.py”, line 43, in
shutil.move(img_filename, dir_name)
File “D:\Python37-32\lib\shutil.py”, line 572, in move
os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: ‘C:\Users\Adminroot\Desktop\app_delete\files\1.png’
Process finished with exit code 1

问题解决:

Image
从源码里面看,它是一个懒加载方法,必须使用其它方法比如 show() 之后才会 close,但是它并没有主动 close 方法,所以我遍历循环使用该图片的时候,报错正在被使用… … 但是具体如何解决呢?用其它包来获取图片的宽,高吗?求解

  相关解决方案