Search code examples
pythoncx-freeze

How to make a cx_freeze executable write on a text file


I am trying to make a python application and I was able to get the folders I needed into the build folder, but whenever the .exe executes the open(SaveFile, "w") command I get PermissionError: [Errno 13] Permission denied. This is my setup.py code:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
# "packages": ["os"] is used as example only
build_exe_options = dict(include_files = ["IMG/", "Saves/"])

# base="Win32GUI" should be used only for Windows GUI app
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "PPD Mover",
    description = "An app to help move files for using PPD",
    options = {"build_exe": build_exe_options},
    executables = [Executable("File.py", base=base)]
)

I don't get any error for reading the file, just for opening it to write on it. Also, I know this might be a duplicate but the only question I found about this was active last time more than 2 years ago so I thought I could ask myself

Edit: I was stupid and I did not understand what I read before, I posted my solution in a comment, I would have closed the question but I don't have enough reputation for it


Solution

  • I solved it by looking at another post. as said here: CX_Freeze - Building a .msi with Admin permissions, it is not supposed to write on text files in a random folder so just moving it to \AppData\Roaming solved the issue