How to rename exe.win-amd64-3.8 folder in cx_Freeze after running setup.py

Viewed 377

I am using cx_Freeze python exe creator. After running the setup.py script, it create the directory like this build/exe.win-amd64-3.8. I want to rename the directory exe.win-amd64-3.8 to runner. I tried with other options using os.rename, but it does not work if I write in setup.py and it gives error like Permission denied. I provide below my setup.py script below.

import shutil

from cx_Freeze import setup, Executable

includes = ["net_util","cx_Freeze","platform", "subprocess"]
excludes = ["tkinter", "test","unittest", "pydoc","http",'multiprocessing.Pool']
packages = ["os", "platform", "net_util","concurrent","subprocess","platform"]
build_exe_options = {"excludes": excludes,"optimize": 2}
mainScript = "main.py"
exeIcon = "icons/ping.ico"
exeName = "pingcheck.exe"

base = None
# if sys.platform == "win32":
#     base = "Win32GUI"


exe = Executable(script=mainScript, base = base, icon=exeIcon,targetName=exeName)
shutil.rmtree('build', ignore_errors=True)

setup(name = "pingExe",
        version = "0.1",
        description = "My Ping Console application!",
        options = {"build_exe": build_exe_options},
        executables = [exe])

Please suggest me about how to rename when I run python setup.py build.

1 Answers

I know I'm very late to this thread, but if anyone else ends up here...

Simply using the command --build-exe runner will do the trick. Also, if you use -b [DIR], that will change the directory that is traditionally build\.

Putting it all together: python setup.py build -b . --build-exe runner will remove the build\ directory and instead simply leave the executable and its dependencies in runner within your current working directory.

Alternatively, you can add "build_exe": runner as another keyword argument within your build_exe_options which will do the equivalent of -b . --build-exe runner. This should look like:

# Stuff before here...
build_exe_options = {
  "build_exe": "runner",
  "excludes": excludes,
  "optimize": 2
}
# More after...
setup(
  name="pingExe",
  version="0.1",
  description="My Ping Console application!",
  options={"build_exe": build_exe_options},
  executables=[exe]
)
Related