'cx-freeze PermissionError: [Errno 13] Permission denied

I am attempting to use cx_Freeze as an alternative to my usual application for converting .py to .exe (auto-py-to-exe). When I run it in cmd I get:

C:\WINDOWS\system32>cxfreeze-quickstart
Project name: FE
Version [1.0]: 1.0
Description: File Edit and more!!!
Python file to make executable from: File Create.py
Executable file name [File Create]: FileCreateExe
(C)onsole application, (G)UI application, or (S)ervice [C]: C
Save setup script to [setup.py]: C:\Users\tom\Documents\python\_Thiswill createfiles_
Overwrite C:\Users\tom\Documents\python\_Thiswillcreatefiles_ [n]? yes
Traceback (most recent call last):
  File "c:\users\tom\appdata\local\programs\python\python38-32\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\tom\appdata\local\programs\python\python38-32\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\tom\AppData\Local\Programs\Python\Python38-32\scripts\cxfreeze-quickstart.exe\__main__.py", line 7, in <module>
  File "c:\users\tom\appdata\local\programs\python\python38-32\lib\site-packages\cx_Freeze\setupwriter.py", line 101, in main
    writer.Write()
  File "c:\users\tom\appdata\local\programs\python\python38-32\lib\site-packages\cx_Freeze\setupwriter.py", line 64, in Write
    output = open(self.setupFileName, "w")
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\tom\\Documents\\python\\_This will create files_'

As you can see I am running my command prompt as administrator since I got the same error when running it normally. What can I do to fix this error? PermissionError: [Errno 13] Permission denied: 'C:\\Users\\tom\\Documents\\python\\_This will create files_'. I can not find any other sites that explain how to fix this. Why does this error occur? Please can I have some help... 😁😁😁



Solution 1:[1]

dude you are running the command from system32

cd to another directory using this command and try again

cd C:/Users/<your name>/Documents

if this doesnt work go here

Solution 2:[2]

Step 1: Add Python to Windows Path
Step 2: Open the Windows Command Prompt as administrator
Step 3: Install the Pyinstaller Package

In the Windows Command Prompt, type the following command to install the pyinstaller package (and then press Enter):

pip install pyinstaller

Step 4: Save your Python Script

I then saved the Python script in the following folder:

C:\Users\Ron\Desktop\MyPython

Where I named the Python script as ‘hello’

Step 5: Create the Executable using Pyinstaller

Now you’ll be able to create the executable from the Python script using pyinstaller.

Simply go to the Command Prompt, and then type:

cd followed by the location where your Python script is stored

In my case, I typed the following in the command prompt:

cd C:\Users\Ron\Desktop\MyPython

Next, use the following template to create the executable:

pyinstaller --onefile pythonScriptName.py

Since in our example, the pythonScriptName is ‘hello‘, then the command to create the executable is:

pyinstaller --onefile hello.py

Once you’re done, press Enter for the last time.

Step 6: Run the Executable

Your executable should now get created at the location that you specified.

In my case, I went back to the location where I originally stored the ‘hello’ script

(C:\Users\Ron\Desktop\MyPython).

Few additional files got created at that location. To find the executable file, open the dist folder:

Now I hope that solves the question..

Solution 3:[3]

Read this doc. Create a setup.py file in your project directory and copy the content from the docs into it.

Modify it as necessary, then run python setup.py build inside your project directory.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Syed
Solution 3