3

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...

Thomas
  • 1,214
  • 4
  • 18
  • 45
  • @PNX can you provide proper example of the file names? I mean, why would you have python file to make executable from as `File Create.py` and Executable file name [File Create] as `File Create Executable`? Also, can you have a folder to save without spaces? `C:\Users\tom\Documents\python\_This will create files_`? – Nagaraj Tantri Jun 10 '20 at 02:05
  • I updated the question @NagarajTantri . I hope this is what you meant? – Thomas Jun 12 '20 at 09:49

3 Answers3

3

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

  • System32 in when you run cmd (and the process) as administrator. – Thomas Jun 12 '20 at 09:47
  • @DiamondDemon The directory separator on Windows is ``\`` and not `/` as on Linux/Mac. Please read the Microsoft article about [Naming Files, Paths, and Namespaces](https://learn.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file) and don't use in future on Windows `/` in file/folder strings as directory separator although Windows replaces them usually all before passing the file/folder string to the file system. Compare output of `for %I in (C:\Windows\*.exe) do @echo %I` with `for %I in (C:/Windows/*.exe) do @echo %I` and look on the difference in output. – Mofi Jun 13 '20 at 18:51
  • @DiamondDemon There is the predefined [Windows environment variable](https://en.wikipedia.org/wiki/Environment_variable#Windows) `USERPROFILE` with path to the user's profile directory which should be used and not `C:/Users/`. A file/folder name should be always enclosed in `"` to always work even on containing for example character `&`. Further it is recommended to use option `/D` on using __CD__ to change directory and if necessary also the drive. So better would be `cd /D "%UserProfile%\Documents"` if the user's shell folder for documents is still the default folder. – Mofi Jun 13 '20 at 18:58
  • @DiamondDemon There is a difference between command working __by chance__ with automatic syntax correction by Windows or working because of being 100% correct written. On my computer the command posted by you would never work because of current directory after opening a command prompt window is by default not on drive `C:` and my user profile directory is not in `C:\Users`, and your command does not work if the user account name contains an ampersand like `Obelix GmbH & Co KG`. SO is a site for programmers on which code should be posted working by design and not by chance. – Mofi Jun 15 '20 at 05:03
1

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..

Syed
  • 31
  • 5
1

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.

zariiii9003
  • 356
  • 1
  • 7