简体   繁体   English

Python Pillow 库错误:PermissionError:[Errno 13] 权限被拒绝

[英]Python Pillow Library Error : PermissionError: [Errno 13] Permission denied

"E:\Extras and Soft\the coder(codes)\PYCharm\sept 2020\scripting in python (course time)\venv\Scripts\python.exe" "E:/Extras and Soft/the coder(codes)/PYCharm/sept 2020/scripting in python (course time)/img2png.py"

**Enter the image directory : pokedesk/
Enter the output directory : pokedesk/new_desk/
1 file done**

Traceback (most recent call last):
  File "E:/Extras and Soft/the coder(codes)/PYCharm/sept 2020/scripting in python (course time)/img2png.py", line 16, in <module>
    img = Image.open(f'{image_folder}{filename}')
  File "E:\Extras and Soft\the coder(codes)\PYCharm\sept 2020\scripting in python (course time)\venv\lib\site-packages\PIL\Image.py", line 2878, in open
    fp = builtins.open(filename, "rb")
PermissionError: [Errno 13] Permission denied: 'pokedesk/new_desk'
1 file done

Process finished with exit code 1

This is the error named Permission Error happening after the processing of the 2 files with the PILLOW library.这是在使用 PILLOW 库处理 2 个文件后发生的名为Permission Error Now there were 4 files I wanted to convert but I get two of them done .现在有 4 个文件我想转换,但我完成了其中的两个。 I will leave you with the screenshot of the code and the error too .我会给你留下代码的截图和错误。 Thanks in advance!提前致谢!

My code:我的代码:

import os
from PIL import Image
# image_folder = sys.argv[1]
# output_folder = sys.argv[2]
image_folder = input("Enter the image directory : ")
output_folder = input("Enter the output directory : ")

# print(image_folder)
# print(output_folder)

if not os.path.exists(output_folder):
    os.makedirs(output_folder)

for filename in os.listdir(image_folder):

    img = Image.open(f'{image_folder}{filename}')

    clean_name = os.path.splitext(filename)[0]

    img.save(f'{output_folder}{clean_name}.png', 'png')

    print('1 file done')

The error that I got:我得到的错误:我得到的错误

试试这个: img = Image.open(f'{image_folder}{filename}','wb')

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM