0

I want to prepare the board for a chess game. For that, I want to plot the images of the chess pieces on the board. On the trying to access the folder with the images of the pieces I receive the following permission error :

Traceback (most recent call last):
File "C:\Users\Murat\PycharmProjects\pythonProject\Chess Game\import image.py", line 19, in
img = PIL.Image.open(x)
File "C:\Users\Murat\PycharmProjects\pythonProject\venv\lib\site-packages\PIL\Image.py", line 2975, in open
**fp = builtins.open(filename, "rb")
PermissionError: [Errno 13] Permission denied: '.idea'".

Even though I have tried to give all access to the folder with the os.chmod(...) cmd. Can anyone tell me what I need to change here to get access/permission to the folder?

import os, sys
from stat import*

import matplotlib
import matplotlib.pyplot as plt
import PIL
import matplotlib.image as mpimg

rows = 2
os.chmod(r'C:\Users\Murat\PycharmProjects\pythonProject\Chess Game\Chess_pieces_images', 0o777)
os.chdir(r'C:\Users\Murat\PycharmProjects\pythonProject\Chess Game\Chess_pieces_images') #path to images
piece_images = os.listdir(r'C:\Users\Murat\PycharmProjects\pythonProject\Chess Game\Chess_pieces_images')


for num, x in enumerate(piece_images):
    img = PIL.Image.open(x)
    plt.subplot(rows, 8, num + 1) #nrows, ncols, index,**kwargs
    plt.title(x.split('.')[0])
    plt.axis('off')
    plt.imshow(img)```
user20650
  • 24,654
  • 5
  • 56
  • 91
Murat999
  • 1
  • 2
  • "Even though I have tried to give all access to the folder with the os.chmod(...) cmd." Individual files have their own permissions, not just the containing folder. The bigger problem is that *you do not want to* try to open the file that's failing, because it is *not an image*. It seems as if you may not have been expecting that file to be there. It seems like you really have a question about how your operating system works, frankly. – Karl Knechtel Dec 11 '21 at 00:18
  • @KarlKnechtel what do you mean exactly by " The bigger problem is that you do not want to try to open the file that's failing, because it is not an image." ? The directory I am leading to is the folder with the images which I want to put into the loop. It should be feasible to open all images with that loop right? FYI I have this example of the loop from here: https://stackoverflow.com/questions/48435229/how-to-plot-a-list-of-image-in-loop-using-matplotlib/48435411. Thank you for your help and answer! – Murat999 Dec 11 '21 at 13:30

0 Answers0