title: PermissionError: [Errno 13] Permission denied on Windows
body: <p>I’m working on a python program that outputs information into an Excel file using the openpyxl library. When I go to save the information using “workbook.save(excel_file_path),” I get &quot;PermissionError: [Errno 13] path\to\output_file.xlsx&quot; message and the program crashes before writing to the file.</p>
  <p>I keep getting directed to this post, but it did not solve my problem: <a href="https://stackoverflow.com/a/36469464">https://stackoverflow.com/a/36469464</a></p>
  <ol>
  <li>Running CMD.exe as an administrator, navigating to my “application.exe” file, and then running it does not work.</li>
  <li>I cannot create a shortcut or batch file to run it with “python.exe application.py” because it imports an external library that is not detectable when run like this. In addition, I plan on running this program on multiple VMs, and would like to avoid downloading and installing Python and the necessary libraries for each one. A single .exe file is the best solution for this.</li>
  <li>I have tried running the .exe file as an administrator by right-clicking on it and clicking “Run as administrator.” I have also tried checking the &quot;Run this program as an administrator&quot; check button in the &quot;properties &gt; compatibility &gt; settings&quot; menu.</li>
  </ol>
  <p>I opened the .exe file’s &quot;properties &gt; security&quot; tab, and it shows that the program should have the necessary permissions to write to a file. When I click the &quot;Advanced&quot; button in the security tab, the Access column has &quot;full control&quot; for each row. This is also the case with the parent directory the Excel file is being saved to.</p>
  <p>Other things to note:</p>
  <ol>
  <li>The program creates a parent directory with os.makedirs() to put the Excel file into if the directory does not exist already. The parent directory is always created before the program crashes, and since the parent directory was made by the program, I’m guessing it would not deny write permissions to files contained within it.</li>
  <li>The Excel file being written to is not open (or it does not exist yet), so it is not because of conflicting file usage.</li>
  <li>The Excel file is located in a different directory from the .exe file. Both the output directory and the .exe file are both on the administrator account in two different Desktop subdirectories.</li>
  <li><em>The program works fine in PyCharm</em>, but not in the .exe created from Pyinstaller.</li>
  </ol>
  <p>My OS is Windows 10, but I have also had this same problem on my old Windows 7 computer involving a text file. Python 3.8 and Pyinstaller 4.2 are being used for this.</p>