Rodrigo Carvalho
Rodrigo Carvalho

Reputation: 29

PermissionDenied saving files via a pyinstaller executable, works in VS Code

import os
import time
from PIL import ImageGrab

IMAGES_DIR = 'Estudos3\images'

FILENAME_FORMAT = 'screenshot_{}.png'

def take_screenshot():
    filename = FILENAME_FORMAT.format(int(time.time()))

    filepath = os.path.join(IMAGES_DIR, filename)

    ImageGrab.grab().save(filepath)

take_screenshot()

This python code takes a print of the screen and puts it in images, it works perfectly when I run it through vscode, the problem in question is that when I use PyInstaller to transform it into .exe and run it with ./ex.exe it displays an error of PermissionError: [Errno 13] Permission denied: 'Estudos3\images\screenshot_1683919164.png'

Upvotes: 0

Views: 184

Answers (1)

Logan
Logan

Reputation: 5

I recommend checking bwoodsend answer here:

https://github.com/orgs/pyinstaller/discussions/5468

You may also need to run the command prompt as admin before running the executable depending on if the folder you are writing to has security permissions (e.g. only accessible by admin)

Upvotes: 0

Related Questions